The return value of "mktime" in different time zone

本文探讨了mktime函数在处理不同时间区域时的行为特点,特别是在处理UTC前方时区(如开罗)时可能出现的问题。文章指出,mktime函数实际上是返回自1970年1月1日00:00:00 UTC以来的秒数,经过当前时区调整。

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 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值