Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Microsoft C 6.0 - <b>localtime() convert time from long to structure-local correction</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 localtime()             Convert Time from Long to Structure-Local Correction

 #include   <time.h>

 struct tm  *localtime(time);
 time_t *time;                           Pointer to stored time

    localtime() converts 'time' from a long value and stores the result
    in a structure of type 'tm'.  'time' is returned from the function
    time() and represents the number of seconds since 00:00:00, Jan 1,
    1970, Greenwich mean time.

 localtime() breaks down the 'time' value and corrects for the local time
 zone and daylight saving time if the environment variable TZ has been set
 (see below).

    The structure 'tm' is defined in <time.h>.  The fields of structure
    'tm' store the following values:

          'tm_sec'        Seconds (0-59)
          'tm_min'        Minutes (0-59)
          'tm_hour'       Hours (0-23)
          'tm_mday'       Day of month (1-31)
          'tm_mon'        Month (0-11; Jan = 0)
          'tm_year'       Year (current year minus 1900)
          'tm_wday'       Day of the week (0-6; Sun = 0)
          'tm_yday'       Day of the year (0-365; Jan1 = 0)
          'tm_isdst'      Non-zero if daylight saving time, zero if standard
                          time.

    The environment variable TZ can be set using putenv().  The value of
    TZ must be:

        a three-letter abbreviation for a time zone (such as EST),
        followed by

            a signed or unsigned number giving the difference (in hours)
            between Greenwich mean time and the local time zone, and,

            if daylight saving time is in effect, a three-letter daylight
            saving time name.

    "PST8PDT" is a valid TZ value for the Pacific time zone and is the
    default value if TZ has not been set.   When TZ is set, three other
    environment variables are automatically set:

            'timezone'      The difference in seconds between Greenwich
                            mean time and local time

            'daylight'      Nonzero value if daylight saving time is
                            specified by TZ; otherwise 0

            'tzname[0]'     The string value of the three-letter time
                            zone name specified by TZ

            'tzname[1]'     The string value of daylight saving time
                            zone, or empty string if daylight saving
                            time zone was omitted from the TZ setting

    Returns:    If successful, a pointer to the structure result; NULL is
                returned if 'time' refers to a date before 1980.

       Note:    gmtime() and localtime() use a single and statically
                allocated buffer for each conversion.  Each call to
                either of these routines destroys the result of the
                previous call.

 Compatibility: MSC version 4.0 returned a structure representation of
                "00:00:00 January 1, 1980" if 'time' referred to a date
                before 1980.

 Portability:   The tz variable is a Microsoft extension and should not
                be used if ANSI compatibility is required.

   -------------------------------- Example ---------------------------------

    The following statements get the elapsed time in seconds, convert the
    value and store information in the struct 'tm', then print out the
    elements of 'tm'.

           #include <time.h>
           #include <stdio.h>

           struct tm *adjtime;

           main()
           {
               long elapstime;

               time(&elapstime);
               adjtime = localtime(&elapstime);
               printf("date:  %02d/%02d/%02d\n",adjtime->tm_mon,
                       adjtime->tm_mday,adjtime->tm_year);
               printf("time:  %02d:%02d:%02d\n',adjtime->tm_hour,
                       adjtime->tm_min,adjtime->tm_sec);
           }



See Also: asctime() ctime() gmtime() time() tzset()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson