FIX: localtime() Does Not Always Switch to Standard Time (148681)
The information in this article applies to:
- The C Run-Time (CRT), when used with:
- Microsoft Visual C++ for Windows, 16-bit edition 1.5
- Microsoft Visual C++ for Windows, 16-bit edition 1.51
- Microsoft Visual C++ for Windows, 16-bit edition 1.52
- Microsoft Visual C++, 32-bit Editions 2.0
- Microsoft Visual C++, 32-bit Editions 2.1
- Microsoft Visual C++, 32-bit Editions 2.2
- Microsoft Visual C++, 32-bit Editions 4.0
This article was previously published under Q148681 SYMPTOMS
The C run-time function localtime() incorrectly fills the tm_isdst member
of the returning struct tm when it is executed in a time zone that does not
switch from Daylight Savings to Standard time on the same date that the
U.S. time zones make the switch.
CAUSE
The C Runtime Function localtime() is apparently not considering the time
zone. Instead, it is assuming that the switch to Standard time always
occurs on the last Sunday in October.
RESOLUTION
Choose one of the following two workarounds:
- Use the return value of the Win32 SDK function GetTimeZoneInformation,
which returns a DWORD. A return value of TIME_ZONE_ID_STANDARD or
TIME_ZONE_ID_DAYLIGHT will indicate whether the system time has been
adjusted for daylight savings time. GetTimeZoneInformation correctly
considers the current system time zone settings and adjusts on the
proper date. (See the documentation for GetTimeZoneInformation, as there
are other possible return values.)
-or-
- Obtain the source for the C Run-time Library, and modify the localtime
function to adjust according to the current system time zone setting.
The C Run-time Library source is available in several locations. For
instructions about how to obtain the C Runtime Library Source, please
see the following article in the Microsoft Knowledge Base:
For Visual C++ 2.x:
123464
How to Obtain Visual C++ 2.0 Run-Time Library Source Code
NOTE: localtime is defined in the file Localtim.c. Windows NT and
Windows 95 both account for the different dates by way of the
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation
registry entry, which is changed when the time zone changes in the
control panel.
STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed
at the beginning of this article. This bug was corrected in Microsoft
Visual C++, 32-bit Edition, version 4.1.
Modification Type: | Major | Last Reviewed: | 12/8/2003 |
---|
Keywords: | kbbug kbCRT kbfix kbList KB148681 |
---|
|