将unix时间戳字符串转换为可读日期我有一个字符串,表示Python中的Unix时间戳(即“1284101485”),我希望将它转换为可读的日期。当我用time.strftime,我得到一个TypeError:>>>import time
>>>print time.strftime("%B %d %Y", "1284101485")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: argument must be 9-item sequence, not str
3 回答
饮歌长啸
TA贡献1951条经验 获得超3个赞
datetime
from datetime import datetime ts = int("1284101485")# if you encounter a "year is out of range" error the timestamp# may be in milliseconds, try `ts /= 1000` in that caseprint(datetime.utcfromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S'))
阿晨1998
TA贡献2037条经验 获得超6个赞
datetime.datetime.utcfromtimestamp(posix_time).strftime('%Y-%m-%dT%H:%M:%SZ')
添加回答
举报
0/150
提交
取消