【发布时间】:2021-12-18 00:47:02
【问题描述】:
我一直在试图找出我的 for 循环出了什么问题。为什么这会在所有 UNIX 日期变量中附加相同的 UNIX 时间戳?
now = datetime.datetime.today()
dates = []
for x in range(7):
d = now - timedelta(days=x)
dates.append(d.strftime("%Y/%m/%d"))
print(dates)
unixdates = []
for date in dates:
e = time.mktime(datetime.datetime.strptime(datetime.date.today().strftime("%m/%d/%Y"), '%m/%d/%Y').timetuple())
unixdates.append(e)
print(unixdates)
这是输出:
['2021/11/03', '2021/11/02', '2021/11/01', '2021/10/31', '2021/10/30', '2021/10/29', '2021/10/28']
[1635912000.0, 1635912000.0, 1635912000.0, 1635912000.0, 1635912000.0, 1635912000.0, 1635912000.0]
【问题讨论】: