Chinaunix
标题:
python中时间字符串和秒数的相互转换
[打印本页]
作者:
zpp71
时间:
2008-11-25 23:50
标题:
python中时间字符串和秒数的相互转换
1)秒数 ===》字符串
from time import *
def secs2str(secs):
return strftime("%Y-%m-%d %H:%M:%S",localtime(secs))
2)字符串 ===》秒数
from time import *
先将时间字符串解析为9元组,例如:
2008-11-25 23:51:20,解析为9元组:[2008,11,25,23,51,20,0,0,0]。
>>> tmlist = [2008,11,25,23,51,20,0,0,0]
>>> mktime(tmlist)
1227628280.0
本文来自ChinaUnix博客,如果查看原文请点:
http://blog.chinaunix.net/u1/44543/showart_1666183.html
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2