# coding = utf-8
import datetime
dd = raw_input("Please enter date , format is YYYYMMDD:")
"""把字符串类型转为日期类型,strptime"""
dd = datetime.datetime.strptime(dd,"%Y%m%d")
"""把日期类型dd转为time.struct_time(tm_year=2017, tm_mon=2, tm_mday=12, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=6, tm_yday=43, tm_isdst=-1),并获取其中的tm_yday,获取在一年中的天数"""
dd.timetuple().tm_yday
运行结果如下:
Please enter date ,format is YYYYMMDD:20170416
106