您的位置:首页 > 编程语言 > Python开发

python datetime.timedelta(时间差)

2012-07-18 14:51 295 查看
http://hi.baidu.com/paulau/blog/item/22139b08cd6039930a7b82e4.html

http://www.crifan.com/python_time_not_support_timedelta_while_datetime_support/

>>> import time, datetime
>>> d = datetime.datetime(*time.localtime()[:6])
>>> print d2007-09-04 10:10:00
>>> d + 15
Traceback (most recent call last):
File "", line 1, in
TypeError: unsupported operand type(s) for+: 'datetime.datetime' and 'int'
>>> d
datetime.datetime(2007, 9, 4, 10, 10)
>>> t = datetime.timedelta(days=15)
>>> d - tdatetime.datetime(2007, 8, 20, 10, 10)
>>> x = d - t
这样就可以得到表示 15 天前的那个时间对象。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: