Parsing EDT timezone using strptime

Viewed 26

I am trying to parse a simple date-time string in EDT timezone to a datetime object using strptime; however, it runs into an error:

from datetime import datetime
datetime.strptime('2022-05-22 15:02:48 EDT', "%Y-%m-%d %H:%M:%S %Z")


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
C:\..../1902312626.py in <module>
----> 1 datetime.strptime('2022-05-22 15:02:48 EDT', "%Y-%m-%d %H:%M:%S %Z")

~\....\_strptime.py in _strptime_datetime(cls, data_string, format)
    566     """Return a class cls instance based on the input string and the
    567     format string."""
--> 568     tt, fraction, gmtoff_fraction = _strptime(data_string, format)
    569     tzname, gmtoff = tt[-2:]
    570     args = tt[:6] + (fraction,)

~\....\_strptime.py in _strptime(data_string, format)
    347     found = format_regex.match(data_string)
    348     if not found:
--> 349         raise ValueError("time data %r does not match format %r" %
    350                          (data_string, format))
    351     if len(data_string) != found.end():

ValueError: time data '2022-05-22 15:02:48 EDT' does not match format '%Y-%m-%d %H:%M:%S %Z'

But if I change the timezone to UTC, the error disappears.

0 Answers
Related