我想创建一个日期列表,从今天开始,然后返回任意天数,例如在我的示例中为 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)]