我想迭代for循环中的日期。 样本日期: 20170101 20170107
输出应该是: 20170101 20170102 20170103 20170104 20170105 20170106 20170107
答案 0 :(得分:-1)
datetime.strptime就是你要找的东西
start = 20170101
end = 20170107
dates = []
for i in range(start, end):
dates.append(datetime.strptime(str(i), "%Y%m%d"))
日期将有:
[datetime.datetime(2017, 1, 1, 0, 0), datetime.datetime(2017, 1, 2, 0, 0), datetime.datetime(2017, 1, 3, 0, 0), datetime.datetime(2017, 1, 4, 0, 0), datetime.datetime(2017, 1, 5, 0, 0), datetime.datetime(2017, 1, 6, 0, 0)]