我想弄清楚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
>>>> …Run Code Online (Sandbox Code Playgroud) 我测试了以下代码:
date_string = "16:30"
date = datetime.strptime(date_string, "%H:%M")
timestamp = datetime.timestamp(date)
print(timestamp)
Run Code Online (Sandbox Code Playgroud)
但我收到错误:
OSError: [Errno 22] 参数无效
我应该怎么做才能获取时间的时间戳?