from dateutil import rrule from datetime import datetime import time #计算日期差 untilYear = 2018 untilMonth = 5 untilDay = 1 # 2018年第一天 firstDay = datetime(untilYear,1,1) endDay = datetime(untilYear,untilMonth,untilDay) #rrule.DAILY计算天差,此外还有 星期(WEEKLY),年(YEARLY) days = rrule.rrule(freq = rrule.DAILY,dtstart=firstDay,until=endDay) print('相差:',days.count(),'天') 相差: 121 天