Converting time to epoch (Python) [duplicate]

倖福魔咒の 提交于 2019-12-05 11:28:25

You have to convert the string to time tuple -by appropriate spec, and then time tuple to EPOCH time. In Python it's a little bit awkward

import time
time_tuple = time.strptime('2017-01-17 14:36:26', '%Y-%m-%d %H:%M:%S')
time_epoch = time.mktime(time_tuple)

The result is 1484656586.0

I don't know the type of created but this should work:

from datetime import datetime

print(datetime.strptime(str(created), '%Y-%m-%d %H:%M:%S').strftime('%s'))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!