The _localtime32_s function converts a time stored as a time_t value and stores the result in a structure of type tm. The long value timer represents the seconds elapsed since midnight (00:00:00), January 1, 1970, UTC. This value is usually obtained from the time function.
_localtime32_s corrects for the local time zone if the user first sets the global environment variable TZ. When TZ is set, three other environment variables (_timezone, _daylight, and _tzname) are automatically set as well. If the TZ variable is not set, localtime32_s attempts to use the time zone information specified in the Date/Time application in Control Panel. If this information cannot be obtained, PST8PDT, which signifies the Pacific time zone, is used by default. See _tzset for a description of these variables. TZ is a Microsoft extension and not part of the ANSI standard definition of localtime.
Note |
|---|
| The target environment should try to determine whether daylight saving time is in effect. |
_localtime64_s, which uses the __time64_t structure, allows dates to be expressed up through 23:59:59, December 31, 3000, coordinated universal time (UTC), whereas _localtime32_s represents dates through 03:14:07 January 19, 2038, UTC.
In Visual C++ 2005, localtime_s is an inline function which evaluates to _localtime64_s, and time_t is equivalent to __time64_t. If you need to force the compiler to interpret time_t as the old 32-bit time_t, you can define _USE_32BIT_TIME_T. Doing this will cause localtime_s to evaluate to _localtime32_s. This is not recommended because your application may fail after January 19, 2038, and it is not allowed on 64-bit platforms.
The fields of the structure type tm store the following values, each of which is an int.
- tm_sec
-
Seconds after minute (0 – 59).
- tm_min
-
Minutes after hour (0 – 59).
- tm_hour
-
Hours after midnight (0 – 23).
- tm_mday
-
Day of month (1 – 31).
- tm_mon
-
Month (0 – 11; January = 0).
- tm_year
-
Year (current year minus 1900).
- tm_wday
-
Day of week (0 – 6; Sunday = 0).
- tm_yday
-
Day of year (0 – 365; January 1 = 0).
- tm_isdst
-
Positive value if daylight saving time is in effect; 0 if daylight saving time is not in effect; negative value if status of daylight saving time is unknown. If the TZ environment variable is set, the C run-time library assumes rules appropriate to the United States for implementing the calculation of daylight saving time (DST).