python linux时间戳到日期时间和反向
发布时间:2020-12-16 23:36:59 所属栏目:Python 来源:网络整理
导读:我想知道如何将日期时间转换为 Linux时间戳13668315 Wed Apr 24 19:25:06 2013 GMT (13位),并使用python反转. 例如: Wed Apr 24 19:25:06 2013 GMT 至 从 至 13668315 Wed Apr 24 19:25:06 2013 GMT Wed Apr 24 19:25:06 2013 GMT13668315 Wed Apr 24 19:25
我想知道如何将日期时间转换为
Linux时间戳13668315
Wed Apr 24 19:25:06 2013 GMT (13位),并使用python反转. 例如: Wed Apr 24 19:25:06 2013 GMT 至
解决方法
从字符串到时间戳,使用
time.strptime() ,将生成的struct_time元组传递给
time.mktime() ;您的时间戳使用毫秒,而不是UNIX秒作为浮点值,因此您需要乘以1000:
import time datestr = "Wed Apr 24 19:25:06 2013 GMT" time.mktime(time.strptime(datestr,"%a %b %d %H:%M:%S %Y %Z")) * 1000 在另一个方向,使用
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |