DOCERR: mktime Fails for January 1, 1970 in Several Time ZonesLast reviewed: March 20, 1998Article ID: Q148790 |
The information in this article applies to:
SUMMARYFor time zones that are ahead of Greenwich Mean Time such as Cairo's time zone (GMT + 2, which means the time in Cairo is two hours ahead of GMT), calling mktime with its argument set to correspond to January 1, 1970 00:00:00 (midnight), returns -1 (failure). The Visual C++ 4.0 Books Online states:
mktime handles dates in any time zone from midnight, January 1, 1970, to midnight, February 5, 2036. MORE INFORMATIONThe problem is not that mktime is in error, it is the documentation's claim that this function will handle midnight January 1, 1970 in any time zone. Actually mktime returns the number of seconds that have elapsed since January 1, 1970 00:00:00, adjusted for the current time zone. Adjusted for current time zone means that the appropriate number of seconds will be added or subtracted such that mktime actually returns the number of seconds elapsed since midnight January 1, 1970 Greenwich Mean Time (GMT). This means that, for example, calling mktime for January 1, 1970 in the Pacific Time Zone (GMT - 8) returns 28800, which happens to be the number of seconds in 8 hours. The return value of 28800 in the Pacific Time Zone means that 28800 seconds have elapsed since January 1, 1970 00:00:00 GMT when it is the same time in the Pacific Time Zone. The problem occurs in time zones that are ahead of Greenwich Mean Time. Calling mktime in Cairo (GMT + 2), for example, would have to return -1 for January 1, 1970 00:00:00, as January 1, 1970 00:00:00 had not yet occured in GMT when the same time happened in Cairo.
|
Additional query words: vcbuglist400
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |