推算几天后的日期
import datetime
def inputdate():
indate = input("请输入开始日期(20190505)后按键(输入唯恐默认为当天):")
indate = indate.strip()
if len(indate)==0:
return datetime.date.today()
else:
if len(indate)==8:
datester=indate[0:4]+"-"+indate[4:6]+"-"+indate[6:8]
return datetime.datetime.strptime( datester,"%Y-%m-%d")
else:
print("输入错误,将按当前日期推算!!")
return datetime.date.today()
print("********推算几天后的日期********")
sdate=inputdate()
innum= input("请输入间隔天数后按键(输入负数则往前计算):")
if int(innum)!=0:
fdate=sdate +datetime.timedelta(days=int(innum))
fdate=datetime.datetime.strftime( fdate ,"%Y-%m-%d")
print("你推算的日期是: "+ str(fdate))
else:
print("输入错误,程序将退出!!")