Python 2.5 在 datetime.strptime 格式上失败
我看到有人问同样的问题,但没有一个答案对我有帮助。
我收到此错误:
pydev debugger: starting
Traceback (most recent call last):
>>>
File "/usr/local/zend/apache2/htdocs/pyth/src/conn.py", line 23, in <module>
userConnDate = datetime.strptime(data[1] + ' ' + data[2], "%y-%m-%d %H:%M:%S")
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/_strptime.py", line 330, in strptime
(data_string, format))
ValueError: time data did not match format: data=2010-03-11 08:35:25 fmt=%y-%m-%d %H:%M:%S
它对我来说看起来很好,python 看到了什么我没有看到?
谢谢你的时间。
I have seen several questions with people asking about the same problem but none of the answers are helping me.
I'm receiving this error:
pydev debugger: starting
Traceback (most recent call last):
>>>
File "/usr/local/zend/apache2/htdocs/pyth/src/conn.py", line 23, in <module>
userConnDate = datetime.strptime(data[1] + ' ' + data[2], "%y-%m-%d %H:%M:%S")
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/_strptime.py", line 330, in strptime
(data_string, format))
ValueError: time data did not match format: data=2010-03-11 08:35:25 fmt=%y-%m-%d %H:%M:%S
It looks fine to me, what is python seeing that I don't?
Thanks for you time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您正在使用
%y
(与 2 位数字年份匹配)。尝试使用
%Y
,它匹配 4 位数年份(例如 2010)you are using
%y
(which matches a 2 digit year).try with
%Y
, which matches a 4 digit year (like your 2010)尝试使用大写 Y - '%Y' 来匹配 4 位数年份。
Try using the a capital Y - '%Y' to match a 4-digit year.