为什么datetime无法在Windows上转换为<86400的时间戳? [重复]

问题描述 投票:1回答:1

此问题已经在这里有了答案:

我想知道为什么下面的代码

from datetime import datetime
datetime.fromtimestamp(0).timestamp()

在Linux上通过返回0正常运行,但在Windows上使用timestamp()调用OSError期间失败。

我迅速检查了上述单行代码在Windows上的域,它似乎适用于大于或等于86400的时间戳,即1970-01-02T01:00:00。低于此值,时间戳将正确转换为datetime,从而无法生成时间戳。

datetime是否有任何理由可以从[0, 86400)范围内的时间戳正确转换,但在Windows上无法转换回时间戳?

python windows python-3.7 unix-timestamp python-datetime
1个回答
1
投票
存在问题#29097(https://bugs.python.org/issue29097),该问题已在Windows的Python 3.6上报告,现在应修复。
© www.soinside.com 2019 - 2024. All rights reserved.