I am comparing two timestamps parsing. One is:
datetime.datetime.strptime("2022-10-20 13:13:13 UTC", "%Y-%m-%d %H:%M:%S %Z")
which returns datetime.datetime(2022, 10, 20, 13, 13, 13)
.
Note that it neither fail (i.e. it parses the UTC
part) nor add a time zone to the resulting object.
The second parsing is:
datetime.datetime.strptime("2022-10-20 13:13:13 +00:00", "%Y-%m-%d %H:%M:%S %z")
which returns datetime.datetime(2022, 10, 20, 13, 13, 13, tzinfo=datetime.timezone.utc)
with the correct time zone.
As far as I understand the technical note #6 here, both should yield the same results.
I don't understand the difference, nor how the output of the 1st case is the expected one and aligns with the documentation. I would love to have an explanation on the first case. PS: I would like to avoid using dateutil
.
EDIT: I'll try to focus my question. How can I parse the string "2022-10-20 13:13:13 UTC"
and get a time zone aware datetime
object?