Python 2.5 在 datetime.strptime 格式上失败

发布于 2024-08-25 21:41:27 字数 612 浏览 5 评论 0原文

我看到有人问同样的问题,但没有一个答案对我有帮助。

我收到此错误:

    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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蓝戈者 2024-09-01 21:41:27

您正在使用 %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)

绝影如岚 2024-09-01 21:41:27

尝试使用大写 Y - '%Y' 来匹配 4 位数年份。

Try using the a capital Y - '%Y' to match a 4-digit year.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文