判断今天是今年的第几天

Posted on 2020-10-16 11:23  黑炽  阅读(290)  评论(0编辑  收藏  举报
 1 import time
 2 
 3 date = time.localtime()
 4 year, month, day = date[:3]
 5 day_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
 6 
 7 if year % 400 == 0 or (year % 4 == 0 and year % 100 != 0):
 8     day_month[1] = 29
 9 if month == 1:
10     print(day)
11 else:
12     print(sum(day_month[:month - 1]) + day)
13