FIX: Negative Value Passed to mktime() Generates Wrong DateLast reviewed: September 18, 1997Article ID: Q130769 |
The information in this article applies to:
SYMPTOMSThe wrong date is returned when a negative value is passed for the month to the mktime() function. For example, in the sample code in this article, -1 is passed for the month, so the mktime() function should return December 15, 1994. However, it incorrectly returns January 16, 1995.
RESOLUTIONVerify that the value for the month is greater than or equal to zero, when calling the mktime() function.
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.0.
MORE INFORMATION
Sample Code to Reproduce Problem
/* Compile options needed: none */ #include <time.h> #include <stdio.h> void main() { time_t CurrentTime, NewTime; struct tm TimeStruct; time ( &CurrentTime ); TimeStruct = *localtime(&CurrentTime); TimeStruct.tm_mday = 15; TimeStruct.tm_mon = -1; TimeStruct.tm_year = 95; NewTime = mktime (&TimeStruct); printf("%s", asctime( &TimeStruct)); } |
Additional query words: 9.00 9.10
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |