小编Mar*_*ram的帖子

datetime.fromisoformat 的文档示例引发无效的 isoformat 字符串错误

在Python 3.10.8中,如果我写

from datetime import datetime
print(datetime.fromisoformat('2011-11-04T00:05:23Z'))
Run Code Online (Sandbox Code Playgroud)

我收到错误

from datetime import datetime
print(datetime.fromisoformat('2011-11-04T00:05:23Z'))
Run Code Online (Sandbox Code Playgroud)

这是令人惊讶的,因为这个例子是直接取自datetime模块文档的:

>>> from datetime import datetime
# ...
>>> datetime.fromisoformat('2011-11-04T00:05:23Z')
datetime.datetime(2011, 11, 4, 0, 5, 23, tzinfo=datetime.timezone.utc)
Run Code Online (Sandbox Code Playgroud)

这是文档中的错误还是错误?

python datetime python-3.x python-datetime

4
推荐指数
1
解决办法
1637
查看次数

标签 统计

datetime ×1

python ×1

python-3.x ×1

python-datetime ×1