Skip to main content
 首页 » 编程设计

python之为什么 time.strptime ("Sept. 30, 2014", "%b. %d, %Y") 不工作

2025年05月04日41lovecherry

我正在尝试在 python 中解析日期。我的代码适用于除 9 月以外的所有其他月份

这是我的代码

time.strptime("Sept. 30, 2014", "%b. %d, %Y") 

我收到这个错误

ValueError: time data 'Sept. 30, 2014' does not match format '%b. %d, %Y' 

请您参考如下方法:

九月的缩写是Sep,不是Sept。

>>> datetime.strptime("Sep. 30, 2014", "%b. %d, %Y") 
datetime.datetime(2014, 9, 30, 0, 0) 

Here's the list of all abbreviated month names for the en_US local.