@author jackzhenguo
@desc
@date 2020/1/1
import calendar
from datetime import date,datetime
def getEverydaySince(year,month,day,n=10):
i = 0
_, days = calendar.monthrange(year, month)
while i < n:
d = date(year,month,day)
if day == days:
month,day = month+1,0
_, days = calendar.monthrange(year, month)
if month == 13:
year,month = year+1,1
_, days = calendar.monthrange(year, month)
yield d
day += 1
i += 1
测试结果:
In [3]: for day in getEverydaySince(2020,2,1):
...: print(day)
2020-02-01
2020-02-02
2020-02-03
2020-02-04
2020-02-05
2020-02-06
2020-02-07
2020-02-08
2020-02-09
2020-02-10