【问题标题】:dateparser returns wrong date when AM/PM is misspelled当 AM/PM 拼写错误时,dateparser 返回错误的日期
【发布时间】:2021-08-07 18:23:33
【问题描述】:

下面的结果有什么逻辑吗?如何避免它们?

dateparser.parse('6/16/21 11:00 ma')

21 年 8 月 7 日下午 2 点 14 分返回。这是错误的。

dateparser.parse('6/16/21 11:00 eb')

于 2016 年 6 月 21 日晚上 11:00 返回。这是错误的,我们应该更喜欢 eb 是不可解释的并且 dateparser.parse 返回 None。

dateparser.parse('6/16/21 11:00 so')

于 2016 年 6 月 21 日上午 11:00 返回。同样,这是错误的,我们应该更喜欢 dateparser.parse 返回 None。

【问题讨论】:

  • 在调用 dateparser 之前,请自己检查字符串是否以 AM 或 PM 结尾。

标签: python dateparser


【解决方案1】:

查看dateparser.parse functionsettings=参数。

这些设置可以由多个different options 组成。我认为STRICT_PARSINGREQUIRE_PARTS 选项是您所需要的

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-22
    • 2015-06-07
    • 1970-01-01
    • 1970-01-01
    • 2012-01-24
    相关资源
    最近更新 更多