python----一个常用的日期算法模块

 

 

 

 1 from datetime import time,datetime,timedelta
 2 arr = list(map(int,input().split()))
 3 n0,diff = arr
 4 day = n0%100
 5 n0 //=100
 6 month = n0%100
 7 year = n0 // 100
 8 # date0 = time.strftime("%Y-%m-%d",(n0,n2,n1))
 9 date0 = datetime(year,month,day) 
10 # strftime 日期转字符串 obj.strftime("%Y-%m-%d") 或 time.strftime("%Y-%m-%d",obj)
11 # strptime 字符串转日期 datetime.strptime('str','%Y')
12 try:
13     date1 = date0 + timedelta(days=diff)
14     print(date1.strftime("%Y%m%d"))
15 except Exception:
16     print("看情况")

 

posted @ 2020-07-02 01:24  ACruning  阅读(119)  评论(0)    收藏  举报