Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Borland C++ 2.x ( with Turbo 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);
 const time_t *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 necessary), 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 (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.

    localtime() makes these conversions if the environment variable, TZ,
    has been set.  TZ can be set with 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, two 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


       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()
           {
                time_t 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()

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