想创建一个日期列表,从今天开始,然后返回任意天数,例如在我的示例中为100天。有没有比这更好的方法了?
import datetime a = datetime.datetime.today() numdays = 100 dateList = [] for x in range (0, numdays): dateList.append(a - datetime.timedelta(days = x)) print dateList
略胜一筹…
base = datetime.datetime.today() date_list = [base - datetime.timedelta(days=x) for x in range(numdays)]