课堂作业-指定日期的后一天

import datetime
def getday(y=2018,m=2,d=28,n=0):#定义geTday函数,输入一个日期
 the_date = datetime.datetime(y,m,d)#定时时间类
 result_date = the_date + datetime.timedelta(days=n)#两个时间日期的差值
 d = result_date.strftime('%Y-%m-%d')#定义时间输出格式,四位数的年份,月份和天数
 return d#返回函数执行结果
print(getday(2018,2,28,1)) 
print(getday(2019,1,1,-1))

验证了两个时间。2018年2月28和2019年1月1日。结果如下

2018-03-01
2018-12-31
>>> 

 

posted @ 2019-01-02 10:59  潘萧臣  阅读(291)  评论(3)    收藏  举报