I am trying to parse the following datetime value using datetime.strptime:
d = datetime.datetime.strptime('2018-03-26T18:00:00+01:00', "%Y-%m-%dT%H:%M:%Sz")
But getting this error:
ValueError: time data '2018-03-26T18:00:00+01:00' does not match format '%Y-%m-%dT%H:%M:%S%Z'
From my reading of the documentation, %z
should equate to the UTC offset, however if I change the format string to end %S%z
I get a different error:
ValueError: 'z' is a bad directive in format '%Y-%m-%dT%H:%M:%S%z'
Although this question has been marked as a duplicate, I disagree. I am using Python 2.7 which as noted above does not accept the %z
TZ format option, so the approaches mentioned in the comments did not work for me. I finally solved this by using the dateutil
module as mentioned in this post: ISO to datetime object: 'z' is a bad directive
I would therefore like to solve my own question although this seems impossible since the question has been marked a duplicate.