简体   繁体   中英

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. 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.
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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM