修改链接的原始代码:from datetime import datetime, timedelta
def date_range(start, end, interval):
start = datetime.strptime(start, "%Y%m%d")
end = datetime.strptime(end, "%Y%m%d")
diff = (end - start) / interval
for i in range(interval):
if i == 0:
date_additive = 0
else:
date_additive = 1
yield ["{0}-{1}-{2}".format(str(((start + diff * i) + timedelta(days=date_additive)).strftime("%Y").zfill(2)),
str(((start + diff * i) + timedelta(days=date_additive)).strftime("%m").zfill(2)),
str(((start + diff * i) + timedelta(days=date_additive)).strftime("%d").zfill(2))),
"{0}-{1}-{2}".format(str((start + diff * (i + 1)).strftime("%Y").zfill(2)),
str((start + diff * (i + 1)).strftime("%m").zfill(2)),
str((start + diff * (i + 1)).strftime("%d").zfill(2)))]
输入示例:
^{pr2}$
结果:[['2015-03-20', '2015-11-16'], ['2015-11-17', '2016-07-14'], ['2016-07-15', '2017-03-12']]