两个日期之间有条件检查的while循环在我预期的之前结束

2024-05-13 04:39:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我创建代码来生成一个CSV文件,其中包含2013年全年间隔为1小时的日期和时间戳。我的代码是:

from datetime import *
moment=datetime(2013,1,1,0,50)
f = open ("C:\\dates.csv", "w")
while moment<datetime(2014,1,1):
    f.write(str(moment.year)+"."+str(moment.month)+"."+str(moment.day)+";"+str(moment.hour)+":"+str(moment.minute)+"\n")
    moment+=timedelta(minutes=+60)

f.close

问题是代码应该生成2013年全年的代码,但在2013年12月19日01:50之后就停止生成了。我找不到为什么。什么可能是问题所在?在


Tags: 文件csv代码fromimportdatetime间隔时间