datetime python 处理日期时间模块

计算时间差

#!/usr/bin/env python
#coding:utf-8
import datetime
#一般的时间计算
d1 = datetime.datetime(2008, 10, 05,15,50)
d2 = datetime.datetime(2008, 10, 03,21,9,0,0)
d3 = datetime.timedelta(microseconds=5000)
print (d1-d2).microseconds
print (d1-d2).seconds
print (d1-d2).days
print d3
#时区转换,当前系统所在时区+1
d = datetime.datetime.now()
d = d + datetime.timedelta(seconds=3600)
print d
print d.ctime()
python-basic/datetime.txt · 最后更改: 2010/06/02 09:18 (外部编辑)
2007~2011 Copyright @ http://www.pythonclub.org