import sys# 日期处理-日期转换为天数,根据某年过去的天数获取具体的日期classDateHandle:def__init__(self)->None:self.mp ={1:31,3:31,5:31,7:31,8:31,10:31,12:31,4:30,6:30,9:30,11:30,2:28}# 闰年判断defcheck(self, year):if year %400==0or(year %4==0and year %100!=0):returnTruereturnFalse# 获取月份对应的天数definit(self, year):if self.check(year):# 瑞年self.mp[2]=29# 根据年月日获取对应的天数defgetDays(self, year, month, day):cnt =0for m inrange(1, month):cnt += self.mp[m]cnt += dayreturn cnt# 根据某年的天数获取年月日defgetDate(self, year, days):cnt, month =0,1for i inrange(1,13):month = iif cnt + self.mp[i]<= days:cnt += self.mp[i]else:break date = days - cnt return"%d %d %d"%(year, month, date) year, month, day =2025,6,6
d = DateHandle()
d.init(year)
cnt = d.getDays(year, month, day)
date = d.getDate(year, cnt)print('year: %d, month: %d, day: %d , days is %d'%(year, month, day, cnt))print('year is %d, days is %d, conver to date is %s'%(year, cnt, date))##------------------------output--------------------### year: 2025, month: 6, day: 6 , days is 157# year is 2025, days is 157, conver to date is 2025 6 6##------------------------over----------------------##