llooccaallttiimmee() -- Time Function (libc)

Convert system time to calendar structure
#iinncclluuddee <ttiimmee.hh>
#iinncclluuddee <ssyyss/ttyyppeess.hh>
ttmm *llooccaallttiimmee(_t_i_m_e_p)
ttiimmee_tt *_t_i_m_e_p;

llooccaallttiimmee() converts  COHERENT's internal time  into the form  described in
the structure ttmm, which is defined in the header file <ttiimmee.hh>.

_t_i_m_e_p points to the system time.  It is of type ttiimmee_tt, which is defined in
the header file <ssyyss/ttyyppeess.hh>.

llooccaallttiimmee() returns  a pointer to the structure  ttmm. The function aassccttiimmee()
turns ttmm into an ASCII string.

Unlike its  cousin ggmmttiimmee(), llooccaallttiimmee() returns  the local time, including
conversion  to daylight  saving time,  if applicable.   The daylight-saving
time  flag indicates  whether daylight  saving time is  now in  effect, _n_o_t
whether it is in effect during  some part of the year.  Note, too, that the
time zone is set by llooccaallttiimmee() every time the value returned by

    getenv("TIMEZONE")

changes.  See  the Lexicon entry  for TTIIMMEEZZOONNEE for more  information on how
COHERENT handles time zone settings.

_E_x_a_m_p_l_e
The following example recreates  the function aassccttiimmee(). It builds a string
somewhat different  from that returned  by aassccttiimmee() to  demonstrate how to
manipulate the ttmm structure.

#include <time.h>
#include <sys/types.h>

char *month[] = {
    "January", "February", "March", "April",
    "May", "June", "July", "August", "September",
    "October", "November", "December"
};

char *weekday[] = {
    "Sunday", "Monday", "Tuesday", "Wednesday",
    "Thursday", "Friday", "Saturday"
};

main()
{
    char buf[20];
    time_t tnum;
    struct tm *ts;
    int hour = 0;

    time(&tnum);    /* get time from system */

    /* convert time to tm struct */
    ts=localtime(&tnum);

    if (ts->tm_hour == 0)
        sprintf(buf,"12:%02d:%02d A.M.",
            ts->tm_min, ts->tm_sec);

    else
        if(ts->tm_hour>=12) {
            hour=ts->tm_hour-12;
            if (hour==0)
                hour=12;
            sprintf(buf,"%02d:%02d:%02d P.M.",
                hour, ts->tm_min,ts->tm_sec);

        } else
            sprintf(buf,"%02d:%02d:%02d A.M.", ts->tm_hour,
                ts->tm_min,ts->tm_sec);

    printf("\n%s %d %s 19%d %s\n",
        weekday[ts->tm_wday], ts->tm_mday,
        month[ts->tm_mon], ts->tm_year, buf);

    printf("Today is the %d day of 19%d\n",
        ts->tm_yday, ts->tm_year);

    printf("Daylight Saving Time %s in effect\n",
        ts->tm_isdst ? "is" : "is not");
}

_S_e_e _A_l_s_o
ggmmttiimmee(), lliibbcc, ttiimmee [oovveerrvviieeww], TTIIMMEEZZOONNEE
ANSI Standard, section 7.12.3.4
POSIX Standard, section 8.1

_N_o_t_e_s
llooccaallttiimmee() returns  a pointer to a statically allocated  data area that is
overwritten by successive calls.
