Python将时间戳转换为d

2024-04-23 06:54:39 发布

您现在位置:Python中文网/ 问答频道 /正文

使用Python2.7,我有timestamsex:timestampMs 1478001612891

我想把它转换成日期格式。在

我试过datetime.fromtimestamp(int('1478013706323'))

但得到这个错误

Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
ValueError: timestamp out of range for platform localtime()/gmtime() function

Tags: mostinputdatetime格式错误callinteractivefile
1条回答
网友
1楼 · 发布于 2024-04-23 06:54:39

datetime.fromtimestamp需要以秒为单位的输入。把你的数字除以1000.0,然后再传入。在

(根据规范:datetime.fromtimestamp(timestamp)return the local date corresponding to the POSIX timestamp, such as is returned by time.time()。并且time.time()return the time in seconds since the epoch as a floating point number。)

相关问题 更多 >