1. 程式人生 > >python 遍歷日期

python 遍歷日期

python 日期 遍歷

import datetime

start = ‘2016-06-01‘
end = ‘2017-01-01‘

datestart = datetime.datetime.strptime(start, ‘%Y-%m-%d‘)
dateend = datetime.datetime.strptime(end, ‘%Y-%m-%d‘)

while datestart < dateend:
    datestart += datetime.timedelta(days=1)
    print datestart.strftime(‘%Y-%m-%d‘)


python 遍歷日期