I supply "2019-04-05T16:55:26Z"
to Python 3's datetime.datetime.fromisoformat
and get Invalid isoformat string
, though the same string works without the Z. ISO8601 allows for the 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)
In Python ISO 8601 date is represented in YYYY-MM-DDTHH:MM:SS. mmmmmm format. For example, May 18, 2022, is represented as 2022-05-18T11:40:22.519222.
This string is converted into an ISO format string by using the . strftime() method. Here as we know that ISO format is YYYY-MM-DD so we convert it into this format by using the following format code- “%Y-%m-%dT%H:%M:%S. %f%z”.
I just checked the Python 3 documentation and it isn't intended to parse arbitrary ISO8601 format strings:
Caution: This does not support parsing arbitrary ISO 8601 strings - it is only intended as the inverse operation of
datetime.isoformat()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With