我提供"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)
我刚检查了the Python 3 documentation,并不打算解析任意的ISO8601格式字符串:
注意:这不支持解析任意ISO 8601字符串 - 它仅用作
datetime.isoformat()
的逆操作。