日期计算[增加或减少天数]

时间:2019-12-05 16:31:14

标签: python python-3.7

伙计们,我需要编写一个给出日期的程序,然后给出天数,然后得到一个新的日期(天数可以为+或-)。如果有人帮助我,我会很高兴。 (关于第一行和第二行,我只需要在输出中使用它们)

specific_date =input('Enter a date:')
numofdays=input("Enter number of days:")
from datetime import datetime, timedelta
specific_date = datetime(day/month/year)
new_date = specific_date + timedelta(numofdays)

if (year % 400 == 0):
    leap_year = True
elif (year % 100 == 0):
    leap_year = False
elif (year % 4 == 0):
    leap_year = True
else:
    leap_year = False

month=['1','2','3','4','5','6','7','8','9','10','11','12']
if month in (1, 3, 5, 7, 8, 10, 12):
    day in [1,31]
elif month == 2:
    if leap_year:
        day in[1,29]
    else:
        day in[1,28]
        if month in (4,6,9,11):
            day in [1,30]

0 个答案:

没有答案