For time zones that are ahead of Coordinated Universal Time (Greenwich Mean Time), if you call the mktime function with the argument set to correspond to January 1, 1970 00:00:00 (midnight), mktime returns -1 (failure).
For example, this behavior occurs in the time zone for Cairo, Egypt. This time zone is Coordinated Universal Time + 2. This means that the time in Cairo is two hours ahead of Coordinated Universal Time.
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."
===============================================================
The problem is not that the mktime function is in error. Instead, the problem is that the documentation states that this function will handle midnight January 1, 1970 in any time zone. Actually, the mktime function 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 so the mktime function actually returns the number of seconds that have elapsed since midnight January 1, 1970 Coordinated Universal Time. This means that if you call the mktime function for January 1, 1970 in the Pacific Time Zone (Coordinated Universal Time - 8), 28800 is returned. This value is the number of seconds that are contained in 8 hours. The return value of 28800 in the Pacific Time Zone means that 28,800 seconds have elapsed since January 1, 1970 00:00:00 Coordinated Universal Time when it is the same time in the Pacific Time Zone. The problem occurs in time zones that are ahead of Coordinated Universal Time. If you call the mktime function in Cairo (Coordinated Universal Time + 2), a value of -1 is returned for January 1, 1970 00:00:00, because January 1, 1970 00:00:00 had not yet occured in Coordinated Universal Time when the same time happened in Cairo.
Source link: http://support.microsoft.com/kb/148790
本文探讨了mktime函数在处理不同时间区域时的行为特点,特别是在处理UTC前方时区(如开罗)时可能出现的问题。文章指出,mktime函数实际上是返回自1970年1月1日00:00:00 UTC以来的秒数,经过当前时区调整。

4450

被折叠的 条评论
为什么被折叠?



