python 获取当天和前几天时间数据
import datetime from datetime import datetime, date, timedelta def dayDateRange(): dates = [] for i in range(2, -1, -1): yesterday = (date.today() + timedelta(days=-i)).strftime("%Y-%m-%d") # 昨天日期 dates.append(yesterday) return dates if __name__ == '__main__': print(dayDateRange()) pass