日期时间模块中的%b vs%B(python 3)

fmt_1 = '%a %d %B %Y %H:%M:%S %z'
fmt_2 = '%a %d %b %Y %H:%M:%S %z'

t1="Sat 14 Sep 2126 00:36:44 +1400"
code1= dateime.datime.strptime(t1,fmt_1)  #run time error

code2= dateime.datime.strptime(t1,fmt_2)   #right code

为此,我遇到了fmt_1的运行时错误,并通过使用fmt_2进行了修复

%b和%B有什么区别?

评论
rut
rut

From the documentation about Format Codes

  • %b is for Month as locale’s abbreviated name. Like Jan, Feb, …, Dec

  • %B is for Month as locale’s full name. Like January, February, …, December

In Sat 14 Sep 2126 00:36:44 +1400 the month Sep is in abbreviated format so %b fits, wher %B doesn't

点赞
评论