code
import datetime t=datetime.datetime.now() #当前日期 d1 =t.strftime('%Y-%m-%d %H:%M:%S') #7天后 d2=(t+datetime.timedelta(days=7)).strftime("%Y-%m-%d %H:%M:%S") print(d1) print(d2)
输出
macname@MacdeMacBook-Pro Desktop % macname@MacdeMacBook-Pro Desktop % python3 test.py 2021-01-08 17:18:56 2021-01-15 17:18:56 macname@MacdeMacBook-Pro Desktop %