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