一、datetime模块
datetime模块:主要用于时间的修改。
import datetime
导入datetime模块
当前时间
print(datetime.datetime.now()) # 打印时间
2019-08-16 20:17:14.376109
当前时间+3天
now = datetime.datetime.now()
print(now+datetime.timedelta(3)) # 默认+3天
2019-08-19 20:17:14.376109
当前时间+3小时
now = datetime.datetime.now()
print(now+datetime.timedelta(hours=3)) # 3小时
2019-08-16 23:19:58.902024
当前时间+3分钟
now = datetime.datetime.now()
print(now+datetime.timedelta(minutes=3)) # 3分钟
2019-08-16 20:22:58.902024
时间替换
now = datetime.datetime.now()
print(now.replace(year=1997,month=9,day=25,hour=5,minute=20,second=0))
1997-09-25 05:20:00.902024