def dateRange(self, beginDate, endDate):
"""
:param beginDate: string, like "2019-11"
:param endDate: string, like "2020-03"
:return: list
"""
dates = []
dt = datetime.datetime.strptime(beginDate, "%Y-%m")
date = datetime.datetime.strptime(endDate, "%Y-%m")
if dt > date:
dt, date = date, dt
while dt <= date:
if datetime.datetime.strptime(datetime.datetime.strftime(dt, "%Y-%m-%d")[:-3], "%Y-%m") not in dates:
dates.append(dt)
dt = dt + datetime.timedelta(days=1)
if len(dates) > 366:
break
dates = sorted(list(set(dates)))
return dates
生成一个有序的时间列表