在Python中创建日期范围
想创建一个日期列表,从今天开始,然后返回任意天数,例如在我的示例中为100天。有没有比这更好的方法了?
import datetimea = 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)]
以上是 在Python中创建日期范围 的全部内容, 来源链接: utcz.com/qa/426265.html