简体   繁体   中英

Python datetime.strptime() ValueError

I don't understand why I get this error using datetime.strptime(), shouldn't this match?

ValueError: time data '2018-02-01 15:09:02.487779' does not match format '%Y-$m-$d %H:%M:%S.%f'

Mimimal example would be:

from datetime import datetime
print(datetime.strptime('2018-02-01 15:09:02.487779', '%Y-$m-$d %H:%M:%S.%f'))

Thank you in advance!

You have dollar signs instead of percent signs in parts of your format string:

print(datetime.strptime('2018-02-01 15:09:02.487779', '%Y-$m-$d %H:%M:%S.%f'))
                                                          ^  ^

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