我正在尝试使用 Python 版本 3 转换纪元值 -2208988800000
。
我试过在线工具来转换https://www.epochconverter.com/所以我得到的输出是 1/Jan/1900。
import datetime
datetime.datetime.fromtimestamp(-2208988800000 / 1000).strftime('%c')
---------------------------------------------------------------------------
OSError
Traceback (most recent call last)
<ipython-input-15-abaf34dc5003> in <module>()
----> 1 datetime.datetime.fromtimestamp(-2208988800000 / 1000).strftime('%c')
OSError: [Errno 22] Invalid argument
最佳答案
fromtimestamp
行为取决于平台。我使用的是 Windows 10,不支持负值。
摘自 the documentation :
fromtimestamp() may raise ValueError, if the timestamp is out of the range of values supported by the platform C localtime() or gmtime() functions. It’s common for this to be restricted to years in 1970 through 2038.
>>> from datetime import datetime as dt
>>> dt.fromtimestamp(-1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OSError: [Errno 22] Invalid argument
关于python - 无法将 Epoch 值转换为人类可读的日期格式 python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57728111/