这里会显示出您选择的修订版和当前版本之间的差别。
— |
python-basic:datetime [2010/06/02 01:18] (当前版本) |
||
---|---|---|---|
行 1: | 行 1: | ||
+ | ====== datetime python 处理日期时间模块 ====== | ||
+ | ===== 计算时间差===== | ||
+ | |||
+ | <code 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() | ||
+ | </code> |