简体   繁体   中英

ValueError trying to format a date with datetime.strptime in python

If I do this:

dss = datetime.date.today()
print dss.strftime('%d/%m/%y %I:%M %p')

I get: 12/03/13 12:00 AM

But, if I do:

print datetime.datetime.strptime("10/25/09 03:01 AM",'%d/%m/%y %I:%M %p')

I get

ValueError: time data '10/25/09 03:01 AM' does not match format  '%d/%m/%y %I:%M %p'

What am I overlooking?

You are giving a date in m/d/y format when the required format is d/m/y. It is having trouble converting 25 to a month

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