# 交流群: 921673324
from datetime import datetime
from datetime import timedelta
def gen_date(self, start_date_str, end_date_str=None):
start_date = datetime.strptime(start_date_str, '%Y-%m-%d').date()
if end_date_str is None:
end_date_str = '2099-12-31'
end_date = datetime.strptime(end_date_str, '%Y-%m-%d').date()
while start_date < end_date:
yield datetime.strftime(start_date, '%Y-%m-%d')
start_date += timedelta(days=1)
for date_str in gen_date('2010-01-01', '2010-03-03'):
print(date_str)
"""
2010-01-01
2010-01-02
2010-01-03
...
2010-03-02
"""
Python日期生成器
最新推荐文章于 2023-07-29 11:12:21 发布