[2]datetime.timedelta
2020-07-27 本文已影响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()
time1
#日期转为str
print (time1.strftime("%y-%m-%d %H:%M:%S"))
#当前时间后移1小时
print( (time1+timedelta(hours =1)).strftime("%y-%m-%d %H:%M:%S"))