简体   繁体   English

python 3.5和3.6中的奇怪的strptime错误

[英]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 在Python 3.5.3和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. 但在Python 3.7.3中工作正常。

I checked the 3.5 documentation but couldn't spot any changes. 我检查了3.5文档,但没有发现任何变化。 Any ideas? 有任何想法吗?

The %z directive only allows for a colon in the time zone starting with python 3.7. %z指令仅允许以python 3.7开头的时区中的冒号。

See also here 另见这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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