开发者

datetime.strptime () throws 'does not match format' error

开发者 https://www.devze.com 2023-03-03 06:12 出处:网络
I 开发者_如何学Cget time data \'19/Apr/2011:22:12:39\' does not match format \'%d/%b/%y:%H:%M:%S\'

I 开发者_如何学Cget

time data '19/Apr/2011:22:12:39' does not match format '%d/%b/%y:%H:%M:%S'

when using datetime.strptime('19/Apr/2011:22:12:39','%d/%b/%y:%H:%M:%S')

What am I doing wrong?


Try %d/%b/%Y:%H:%M:%S instead - %y right now means 11.

You can "debug" datetime formats easily using date (on the shell and not on python, I mean, assuming you're running GNU/Linux or similar):

date '+%d/%b/%Y:%H:%M:%S'
05/May/2011:09:00:41


You're checking for a 2 digit year ( %y ) instead of a four digit ( %Y )


You want %Y instead of %y. %Y means you want the century, %y is no century and the year is displayed from 00 to 99.

0

精彩评论

暂无评论...
验证码 换一张
取 消