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 - <b>localtime() convert time from int to structure--local correction</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
localtime()              Convert Time from Int to Structure--Local Correction

 #include   <time.h>

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

    localtime() converts a time, stored as a long value, to a structure.
    The 'time' to be converted represents the seconds elapsed since
    00:00:00, Jan 1, 1970, Greenwich mean time.  ('time' is returned from
    the function time().)

    localtime() breaks down the 'time' value, corrects for the local time
    zone and daylight saving time (if needed), and stores the resulting
    time in a structure of type 'tm'.

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

          'tm_sec'        Seconds
          'tm_min'        Minutes
          'tm_hour'       Hours (0-24)
          '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.

    localtime() makes these conversions if the environment variable, TZ,
    has been set.  TZ can be set using putenv().  The value of TZ must
    be:

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

            an optional signed 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:    A pointer to the structure result.  There is no error
                return.

  -------------------------------- 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