FIX: localtime() Does Not Always Switch to Standard TimeLast reviewed: September 19, 1997Article ID: Q148681 |
The information in this article applies to:
SYMPTOMSThe 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.
CAUSEThe 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.
RESOLUTIONChoose one of the following two workarounds:
STATUSMicrosoft 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.
MORE INFORMATIONSome Time Zones switch from Daylight Savings back to Standard Time about a month before most time zones (including the U.S. time zones). GMT + 0200 (Cairo) is an example. In the GMT + 0200 time zone, the switch date is the last Wednesday in September, whereas most other time zones switch on the last Sunday in October. Calling the localtime() CRT to fill in a structure of type tm (defined in Time.h) gives an incorrect result of non-zero for the tm_isdst data member if you call it from one of the time zones that switch early on a date that falls between the two. A non-zero value in the tm_isdst member indicates that the system time has been adjusted for daylight savings time.
Sample Code
/* Compile options needed: None */ #include <iostream.h> #include <time.h> void main(){ tm *loc; time_t clock; time(&clock); tzset(); loc = localtime(&clock); cout << "In timezone GMT+0200, 9-26-1995 is DST, "; cout << "9-27-1995 is not DST" << endl; cout << "The current date and time is: " << asctime(loc) << endl; if(loc->tm_isdst) cout << "It is daylight savings time" << endl; else cout << "It isn't daylight savings time" << endl;}
Steps to Reproduce Problem
|
Additional reference words: localtime
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |