Search code examples
pythondatetimestrptime

Python datetime strptime() does not match format


I get the following error in which you can see the time data and the format I am using

time data '20:07:35 EEDT Wed Mar 31 2021' does not match format '%H:%M:%S %Z %a %b %d %Y'

I used the directives from here and I see that the format matches the description of each directive. Can you see what is the issue here?


Solution

  • import datetime
    
    time = '20:07:35 EEDT Wed Mar 31 2021'
    time = time.replace('EEDT', '+0300')
    datetime.datetime.strptime(time, '%H:%M:%S %z %a %b %d %Y')