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

标签 python datetime

我正在尝试在 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.

关于python - 为什么 time.strptime ("Sept. 30, 2014", "%b. %d, %Y") 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31991435/

相关文章:

sql - Linq2Sql 中的 System.DateTime 和 Sql datetime2(使用 sqlmetal)

python - Django 管理站点无法连接到数据库 - 使用了错误的 mongodb 引擎

python - 使用spaCy替换句子的 "topic"

python - 如何将默认时间(但不是日期)添加到 DJango 中的 DateTimeField?

c# - 托管服务器上的日期时间格式

vba - Range.Find 在 VBA Excel 中不区分一月和十一月(二月和十二月)

java - 当针对 Android API < 26 时,Duration. Between 的最佳替代方案是什么?

python - 包括 Jinja 模板中的 block

python - 赋值是 Python 中的运算符吗?

python - Tensorflow:无法将字符串输入占位符张量