import datetime
now = datetime.datetime.now()
# now = datetime.datetime(2023,4,9)
now.strftime('%Y-%m-%d %H:%M:%S')
# 2023-04-09 21:00:41
# 加7天
delta7 = datetime.timedelta(days=7)
(now+delta7).strftime('%Y-%m-%d %H:%M:%S')
# 2023-04-16 21:00:41
# 减7天
delta7 = datetime.timedelta(days=7)
(now-delta7).strftime('%Y-%m-%d %H:%M:%S')
# 2023-04-02 21:00:41
标签:-%,00,delta7,python,加减,datetime,2023,now
From: https://www.cnblogs.com/wstong2052/p/17301069.html