时间计算
一、几天之后的日期
1 import datetime 2 3 str = "23/09/2021" 4 # 把字符串转成对象 5 toObj = datetime.datetime.strptime(str,'%d/%m/%Y') 6 # 2天之后的日期 7 result = toObj+datetime.timedelta(2) 8 # 把时间对象转化成字符串 9 toStr= datetime.datetime.strftime(result,"%Y-%m-%d")
1 import datetime 2 3 str = "23/09/2021" 4 # 把字符串转成对象 5 toObj = datetime.datetime.strptime(str,'%d/%m/%Y') 6 # 2天之后的日期 7 result = toObj+datetime.timedelta(2) 8 # 把时间对象转化成字符串 9 toStr= datetime.datetime.strftime(result,"%Y-%m-%d")