赞
踩
import datetime
def dateRange(beginDate, endDate):
dates = []
dt = datetime.datetime.strptime(beginDate, "%Y-%m-%d")
date = beginDate[:]
while date <= endDate:
dates.append(date)
dt = dt + datetime.timedelta(1)
date = dt.strftime("%Y-%m-%d")
return dates
if __name__ == '__main__':
print(dateRange("2016-05-26", "2016-05-31"))
结果:
['2016-05-26', '2016-05-27', '2016-05-28', '2016-05-29', '2016-05-30', '2016-05-31']
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。