The return value of "mktime" in different time zone

来源:互联网 发布:dns cache 域名劫持 编辑:程序博客网 时间:2024/05/17 20:27

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 

原创粉丝点击