this is because strptime expects for the %z
format a string that looks like: +0200
not +02:00
, i.e.:
>>> datetime.datetime.strptime('2017-04-26T13:00:00+0200', '%Y-%m-%dT%H:%M:%S%z')
datetime.datetime(2017, 4, 26, 13, 0, tzinfo=datetime.timezone(datetime.timedelta(0, 7200)))
so depending on your context, either you modify the string to fit strptime()
expectations, or you can use a higher level library to handle your dates. Like maya or pendulum, that offer very flexible facilities to handle format parsing and relative date management.
>>> import pendulum, maya # you need to pip install them
>>> pendulum.parse('2017-04-26T13:00:00+02:00')
<Pendulum [2017-04-26T13:00:00+02:00]>
>>> maya.parse('2017-04-26T13:00:00+02:00')
<MayaDT epoch=1493204400.0>