DOCERR: mktime Fails for January 1, 1970 in Several Time Zones

Last reviewed: March 20, 1998
Article ID: Q148790
The information in this article applies to:
  • Microsoft Visual C++ for Windows, versions 1.50, 1.51, 1.52
  • Microsoft Visual C++, 32-bit Edition, versions 2.0, 2.1, 2.2, 4.0, 4.1, 4.2, 5.0

SUMMARY

For 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 INFORMATION

The 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
Keywords : OLDocIss vcbuglist400
Version : Windows:1.5,1.51,1.52; WinNT:2.0,2.1,2.2,4.0,4.1,4.2,5.0
Platform : NT WINDOWS
Issue type : kbdocerr


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: March 20, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.