1、传统套路
import time
#今天的日期,年、月、日
year, month, day = time.localtime()[:3]
#每个月正常的天数
day_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
#闰年2月多一天
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[:month-1])+day)
2、Pythonic
import datetime
today = datetime.date.today()
delta = today - datetime.date(today.year,1,1)+datetime.timedelta(days=1)
print(delta.days)
3、More Pythonic
import datetime
print(datetime.date.today().timetuple().tm_yday)