datetime.datetime.now() # 打印当前时间
# 2019-08-16 19:55:21.141274
now = datetime.datetime.now()
print(now+datetime.timedelta(3)) # 默认+3天
print(now+datetime.timedelta(hours=3)) # 当天时间+3小时
print(now+datetime.timedelta(minutes=3)) # 当天时间+3分钟
now.replace(year=1900)# 替换当前年份
print(datetime.date.fromtimestamp(time.time()))
# 2019-03-07
datetime.datetime.now() + datetime.timedelta(hours=3)# 当前时间-3小时
# 2019-03-07 19:22:14.575881
datetime.datetime.now() + datetime.timedelta(minutes=30)# 当前时间+30分钟
# 2019-03-07 16:52:14.585432
c_time = datetime.datetime.now()# 时间替换
print(c_time.replace(minute=20, hour=5, second=13))
# 2019-03-07 05:20:13.595493
原文:https://www.cnblogs.com/xichenHome/p/11366343.html