【发布时间】:2013-09-23 02:29:39
【问题描述】:
我试图弄清楚 1984 年 3 月 16 日有什么特别之处。在我使用的虚拟机上(没什么特别之处),Python(以及 PyPy)在尝试使用 mktime 时崩溃,似乎是一个完全合理的时间结构。
$ pypy
Python 2.7.3 (f66246c46ca30b26a5c73e4cc95dd6235c966b8f, Jul 30 2013, 09:27:06)
[PyPy 2.0.2 with GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>> import time
>>>> time.mktime((1984,3,16,0,0,0,0,0,0))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OverflowError: mktime argument out of range
>>>> time.mktime((1984,3,15,0,0,0,0,0,0))
448156800.0
>>>> time.mktime((1984,3,17,0,0,0,0,0,0))
448326000.0
>>>> time.mktime((1984,3,16,0,0,0,0,0,0))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OverflowError: mktime argument out of range
>>>>
为什么以及可以做些什么来避免这个问题?
虽然这个问题每次都在这个虚拟机上发生,但我无法让它在任何其他虚拟机上发生。
【问题讨论】:
-
奇怪。在我的机器上没有问题(Mac OS,Python 2.7)。
-
我认为可能是闰秒,但在 1984 年(任何日期)都没有添加,请参阅 en.wikipedia.org/wiki/Leap_second 。我怀疑您的 Python 版本中存在错误...
-
没有什么要补充的,除了我也没有问题。很奇怪。
-
@ShashankGupta :确实归结为系统问题。 “date -d 03/16/1984”返回“无效日期。不过还是很奇怪。
-
你的时区是什么?
标签: python timezone pypy mktime