Home

zhangyiqun

Thoughts, stories and ideas.

Notes Blog Archives About
29 Apr 2010

python时间戳转换

升级某管理程序时使用,解决了时间计算方式不统一的问题

import datetime, time

s= ‘201102111747’

a = datetime.datetime(int(s[0:4]),int(s[4:6]),int(s[6:8]),int(s[8:10]),int(s[10:]))

print int(str(time.mktime(a.timetuple()))[:10])

原型

s = datetime.datetime(2009,1,1)

time.mktime(s.timetuple())

1230739200.0

Notes Blog Archives About