为什么Python 3会发现此ISO8601日期:“2019-04-05T16:55:26Z”无效?

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

我提供"2019-04-05T16:55:26Z"到Python 3的datetime.datetime.fromisoformat并获得Invalid isoformat string,虽然相同的字符串在没有Z的情况下工作.ISO8601允许Z - https://en.wikipedia.org/wiki/ISO_8601

$ python3
Python 3.7.2 (default, Feb 12 2019, 08:15:36)

>>> datetime.fromisoformat("2019-04-05T16:55:26Z")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: Invalid isoformat string: '2019-04-05T16:55:26Z'

>>> datetime.fromisoformat("2019-04-05T16:55:26")
datetime.datetime(2019, 4, 5, 16, 55, 26)
python python-3.x python-3.7 iso8601
1个回答
2
投票

我刚检查了the Python 3 documentation,并不打算解析任意的ISO8601格式字符串:

注意:这不支持解析任意ISO 8601字符串 - 它仅用作datetime.isoformat()的逆操作。

© www.soinside.com 2019 - 2024. All rights reserved.