Python datetime之timedelta
该函数表示两个时间的间隔
参数可选、默认值都为0:datetime.timedelta(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0)
比如要输出当前时间一小时之后的时间:
#coding:utf-8
from datetime import datetime,timedelta
time1 = datetime.now()
print time1
print time1.strftime("%y-%m-%d %H:%M:%S")
print (time1+timedelta(hours =1)).strftime("%y-%m-%d %H:%M:%S")
结果: