[英]datetime.strptime raises valueError because of format mismatch
I am trying to parse a string to a datetime field but it raises the following error:我正在尝试将字符串解析为日期时间字段,但会引发以下错误:
ValueError: time data '15 Dec 1995 00:00 AM' does not match format '%d %b %Y %I:%M %p'
I have checked the python documents and I don't see where the format mismatch is happening.我检查了python 文档,但看不到格式不匹配发生在哪里。 Can anyone help me find where this format error is?谁能帮我找到这个格式错误在哪里?
Looking at the docs:查看文档:
%I %我
Hour (12-hour clock) as a zero-padded decimal number.小时(12 小时制)作为零填充十进制数。
01, 02, …, 12 01, 02, ..., 12
So 00:00:00
is not a valid time under the %I
format, given that 00:00:00 AM
should actually be 12:00:00 PM
所以00:00:00
在%I
格式下不是有效时间,因为00:00:00 AM
实际上应该是12:00:00 PM
There is no 00:00 time in 12-hour clock format, you should either write this as 12:00 or use a 24-hour format with %H. 12 小时制格式中没有 00:00 时间,您应该将其写为 12:00 或使用带有 %H 的 24 小时制格式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.