[英]ValueError: time data '2012-07-19 08:24:00' does not match format '%Y-%m-%d H:M:S'
This is a strange error I think, I am parsing a datetime string in Python, and I believe I am using the correct string format, yet I get the error: 我认为这是一个奇怪的错误,我正在Python中解析日期时间字符串,并且我相信我使用的是正确的字符串格式,但是却收到错误消息:
ValueError: time data '2012-07-19 08:24:00' does not match format '%Y-%m-%d H:M:S' ValueError:时间数据'2012-07-19 08:24:00'与格式'%Y-%m-%d H:M:S'不匹配
Here is the console session log: 这是控制台会话日志:
>>> s='2012-07-19 08:24:00'
>>> import datetime as dt
>>> dt.datetime.strptime(s, '%Y-%m-%d H:M:S')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.6/_strptime.py", line 325, in _strptime
(data_string, format))
ValueError: time data '2012-07-19 08:24:00' does not match format '%Y-%m-%d H:M:S'
Why is a ValueError exception being raised - the specified format matches the string? 为什么引发ValueError异常-指定的格式与字符串匹配?
用这个:
dt.datetime.strptime(s, '%Y-%m-%d %H:%M:%S')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.