python3 获取某段时间内有哪些天数或日历

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']

 

你可能感兴趣的:(python基础)