【发布时间】:2017-04-10 08:35:50
【问题描述】:
我正在尝试将此 unix 时间戳 1491613677888 转换为可读日期。 在这里(stackoverflow)找到了那个python脚本:
import datetime
print(
datetime.datetime.fromtimestamp(
int("1284101485")
).strftime('%Y-%m-%d %H:%M:%S')
)
但是当我把时间戳放在那里时,我得到了那个错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OSError: [Errno 22] Invalid argument
现在我看到我使用的时间戳长了 3 个字符。 我在这个链接上检查了它: http://www.unixtimestamp.com/index.php
并看到它得到了它的时间。 我怎么能用python做到这一点? (我使用的是 python 3.4)
【问题讨论】:
-
无法重现(python2.7 + 3)
-
你的时间戳中最后的 888 是从哪里得到的?第一部分
1491613677是 2017-04-08T01:07:57+00:00,这可能是你想要的。有了它,你的代码就能完美运行。 -
你是从某个以毫秒为单位输出的函数中得到的吗?
-
当我在 Python 2 上使用
int("1284101485888")时,我得到 ValueError: year is out of range,在 Python 3.6 上我得到 42661-07-22 17:11 :28. -
关于@ThierryLathuille 评论。是的,我需要毫秒。我如何在 python 3.4 中使用它?
标签: python unix unix-timestamp