使用Python中time 函数库中的函数求当前系统的日期,并计算当前日期是本年度的第几天。
def isr_year(n):
if (n%40 and n%100!=0)or n%4000:
return True
else:
return False
def conutday(y,m,d):
today=d
if isr_year(y)==True:
lis=[0,31,29,31,30,31,30,31,31,30,31,30]
else:
lis=[0,31,28,31,30,31,30,31,31,30,31,30]
for i in range(m):
today+=lis[i]
print(‘今天是该年份的第{}天。’.format(today))
import time
now=time.strftime("%Y/%m/%d")
year,month,day=now.split("/")
year=int(year)
month=int(month)
day=int(day)
conutday(year,month,day)
在这里插入代码片def isr_year(n):
if (n%4==0 and n%100!=0)or n%400==0:
return True
else:
return False
def conutday(y,m,d):
today=d
if isr_year(y)==True:
lis=[0,31,29,31,30,31,30,31,31,30,31,30]
else:
lis=[0,31,28,31,30,31,30,31,31,30,31,30]
for i in range(m):
today+=lis[i]
print('今天是该年份的第{}天。'.format(today))
import time
now=time.strftime("%Y/%m/%d")
year,month,day=now.split("/")
year=int(year)
month=int(month)
day=int(day)
conutday(year,month,day)