python中如何创建一个日期段?


我想创建一个日期段,比方说,从今天的日期开始,然后走100天,需要显示每天的日期。请问有什么比较好的方式吗?

import datetime
t = datetime.datetime.today()
numdays = 100
dateList = []
for x in range (0, numdays):
    dateList.append(a - datetime.timedelta(days = x))
print dateList

编程 创建 python 日期段 技巧

长-门-有-希 11 years, 1 month ago
import datetime

today = datetime.datetime.today()
dateList = [ today - datetime.timedelta(days=x) for x in range(0,DAYS_YOU_WANT) ]
死神栗子丶 answered 11 years, 1 month ago

Your Answer