简体   繁体   中英

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?

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

See also here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM