日期推算:datetime

>>> import datetime
>>> datetime.datetime.now()
datetime.datetime(2020, 5, 20, 23, 23, 31, 57908)
>>> cur_time = datetime.datetime.now()
>>> cur_time.strftime('%Y-%m-%d')
'2020-05-20'
>>> cur_time+datetime.timedelta(days=20)
datetime.datetime(2020, 6, 9, 23, 24, 16, 160627)
>>> future_time = cur_time+datetime.timedelta(days=20)
>>> future_time.strftime('%Y-%m-%d')
'2020-06-09'

 

posted @ 2020-05-20 23:36  程序法  Views(239)  Comments(0Edit  收藏  举报