0

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:

ValueError: time data '2012-07-19 08:24:00' does not match format '%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?

4

1 に答える 1

4

これを使って:

dt.datetime.strptime(s, '%Y-%m-%d %H:%M:%S')
于 2012-07-24T07:16:57.617 に答える