import time date = time.localtime() print(date) #time.struct_time(tm_year=2018, tm_mon=2, tm_mday=24, tm_hour=19, tm_min=42, tm_sec=57, tm_wday=5, tm_yday=55, tm_isdst=0) year = date[0] month = date[1] day = date[2] day_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] #判断是否为闰年 if year % 400 == 0 or (year % 4 == 0 and year % 100 != 0): day_month[1] = 29 if month == 1: print(day) else: print(sum(day_month[0: month - 1]) + day) #输出结果 #55