【发布时间】:2021-08-26 03:01:51
【问题描述】:
Windows 出现错误:
OSError: [Errno 22] 无效参数
虽然在 Linux 中一切正常
from datetime import datetime
a = datetime.fromtimestamp(0)
a.timestamp() # - an error occurs here
如何在 Windows 中解决此问题?
【问题讨论】:
-
你的预期输出是什么?
-
预期输出 - 0.0
-
不,因为它没有提到 fromtimestamp。时间戳的问题源于使用 fromtimestamp(0) 创建的 datetime 对象
-
对我最初的评论表示歉意,我认为这具有误导性。 this answer 基本上说“这是 Windows 的事情”和“不会发生在有意识的日期时间”(我可以重现)。但是:它没有提供关于 为什么 在 Windows 上发生这种情况的任何线索。无论如何,我的收获是:尽可能使用有意识的日期时间(最好是 UTC)
标签: windows datetime timestamp python-3.9