FIX: time() Function Overcompensates for Daylight Savings Time (182042)
The information in this article applies to:
- The C Run-Time (CRT), when used with:
- Microsoft Visual C++, 32-bit Editions 4.0
- Microsoft Visual C++, 32-bit Editions 4.0a
- Microsoft Visual C++, 32-bit Editions 4.1
- Microsoft Visual C++, 32-bit Editions 4.2b
- Microsoft Visual C++, 32-bit Enterprise Edition 4.2
- Microsoft Visual C++, 32-bit Professional Edition 4.2
This article was previously published under Q182042 SYMPTOMS
The C run-time library time() function may, in some geographic locations
and at certain times, return a time that is off by one hour to the actual
time. This problem is specific to areas that do not use Daylight Savings
Time (Japan, for example, or in parts of Indiana in the United States), and
the problem occurs only at times at the beginning or end of Daylight
Savings Time.
CAUSE
The time() function calls GetLocalTime, which returns the exact time,
compensated for time zones and Daylight Savings Time. However, before the
function ends it also calls the isindst() function. This function uses a
standard formula for determining if the current date and time are part of
Daylight Savings Time. If isindst() returns TRUE, the time is altered by
3600 seconds (one hour).
RESOLUTION
This problem has been corrected in Microsoft Visual C++ versions 5.0 and
later. If you cannot upgrade to Visual C++ 5.0, there are two workarounds
to this problem:
-
Workaround 1. Call GetLocalTime() instead of time(). This method is
documented in the following article in the Microsoft Knowledge Base:
99456 Win32 Equivalents to C Run-Time Functions
- Workaround 2. If possible, start the Date/Time application and clear the
check box to "Automatically adjust clock for daylight saving changes"
(please note that this workaround may not be available in all areas). When
time() is called, GetLocalTime will return the time adjusted for the local
time zone, and isindst will cause time() to adjust the time for Daylight
Savings Time.
STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed
at the beginning of this article. This bug has been corrected in Microsoft
Visual C++, 32-bit edition, versions 5.0 and later.
| Modification Type: | Major | Last Reviewed: | 12/8/2003 |
|---|
| Keywords: | kbbug kbcode kbCRT kbfix kbVC400fix KB182042 kbAudDeveloper |
|---|
|