Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange strptime error in python 3.5 and 3.6

The following code

from datetime import datetime
dt = '2019-07-21T08:54:32.115285+00:00'
datetime.strptime(dt, '%Y-%m-%dT%H:%M:%S.%f%z')

throws the following exception in Python 3.5.3 and 3.6.8

ValueError: time data '2019-07-21T08:54:32.115285+00:00' does not match format '%Y-%m-%dT%H:%M:%S.%f%z'

but works fine in Python 3.7.3.

I checked the 3.5 documentation but couldn't spot any changes. Any ideas?

like image 668
Cornelius Avatar asked Mar 25 '26 21:03

Cornelius


1 Answers

The %z directive only allows for a colon in the time zone starting with python 3.7.

See also here

like image 112
A Monad is a Monoid Avatar answered Mar 27 '26 09:03

A Monad is a Monoid



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!