now_time=
datetime.datetime.now()
print
((now_time+datetime.timedelta(days=+1)).strftime(
"
%Y-%m-%d %H:%M:%S
"
))
#
获取后一天 2018-05-01 15:22:32
print
((tim+datetime.timedelta(hours=-1)).strftime(
"
%Y-%m-%d %H:%M:%S
"
))
#
获取前一小时 2018-05-01 14:23:19
可选参数:
datetime.timedelta(days=0, seconds=0, microseconds=0#毫秒, milliseconds=0, minutes=0, hours=0, weeks=0)
如获取分钟:
print(now_time,(now_time+datetime.timedelta(minutes=+1)).strftime("%Y-%m-%d %H:%M:%S")) #2019-01-07 21:10:16.408863 2019-01-07 21:11:16
时间不需要中间的横杠-或者冒号:可以去掉不影响
current_time = (datetime.datetime.now() - datetime.timedelta(days=0)).strftime("%Y%m%d%H%M%S")