我将 "2019-04-05T16:55:26Z"
提供给 Python 3 的 datetime.datetime.fromisoformat
并得到 Invalid isoformat string
,尽管相同的字符串在没有 https.://Z.8 的情况下也可以工作 -01 Z.://8 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)
原文由 stephendwolff 发布,翻译遵循 CC BY-SA 4.0 许可协议
我刚刚查看 了 Python 3 文档,它并不打算解析任意 ISO8601 格式字符串: