將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
提交
取消