python 输入考试时间和结束时间获得中的的所有时间list

import datetime

start = '2016-05-01'
end = '2016-06-01'
def get_month_list(start,end):
    if start == end:
        return [start.replace("-",'')]
    else:
        st = start.replace("-",'')
        datestart = datetime.datetime.strptime(start, '%Y-%m-%d')
        dateend = datetime.datetime.strptime(end, '%Y-%m-%d')
        print(datestart,dateend)
        daat = list()
        while datestart < dateend:
            datestart += datetime.timedelta(days=1)
            s  = datestart.strftime('%Y%m%d')
            daat.append(s)
        daat.insert(0, st)
        return daat
print(get_month_list(start,end))

你可能感兴趣的:(python 输入考试时间和结束时间获得中的的所有时间list)