当前位置:编程学习 > 网站相关 >>

python时间和时间戳之间的转换

(1)例如格式2012-07-31 00:01:18,根据该时间计算时间戳:

将"2012-03-28 06:53:40"转化为时间戳
s = time.mktime(time.strptime('2012-03-28 06:53:40', '%Y-%m-%d %H:%M:%S'))

(2)根据时间戳得到如2012-07-31 00:01:18的时间格式,显示的时间形式可以根据format指定的

import time

timestamp = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime("2012-07-31 00:01:18"))

 

作者:司马宅
补充:Web开发 , Python ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,