方法一:
import datetime begin = datetime.date(2019, 1, 21) end = datetime.date(2019, 4, 7) for i in range((end - begin).days + 1): day = begin + datetime.timedelta(days=i) print(str(day))
方法二:
import datetime
begin = datetime.date(2014,6,1) end = datetime.date(2014,6,7) d = begin delta = datetime.timedelta(days=1) while d <= end: print (d.strftime("%Y-%m-%d")) d += delta
import datetime def init_date_list(begin_date, end_date): date_list = [] begin_date = datetime.datetime.strptime(begin_date, '%Y%m%d') end_date = datetime.datetime.strptime(end_date, '%Y%m%d') while begin_date<=end_date: date_str = begin_date.strftime('%Y%m%d') date_list.append(date_str) begin_date += datetime.timedelta(days=1) return date_list