簡體   English   中英

使用Python解析模糊時間戳

[英]fuzzy timestamp parsing with Python

是否有一個Python模塊來解釋模糊時間戳,如unix中的date命令:

> date -d "2 minutes ago"
Tue Aug 11 16:24:05 EST 2009

到目前為止我發現的最接近的是dateutil.parser,它對於上面的例子是失敗的。

謝謝

看看這個開源模塊: parsedatetime

我一直在嘗試使用pyparsing - 你可以在這里找到我的最新嘗試。 它適用於這些測試用例:

today
tomorrow
yesterday
in a couple of days
a couple of days from now
a couple of days from today
in a day
3 days ago
3 days from now
a day ago
now
10 minutes ago
10 minutes from now
in 10 minutes
in a minute
in a couple of minutes
20 seconds ago
in 30 seconds
20 seconds before noon
20 seconds before noon tomorrow
noon
midnight
noon tomorrow

dateparser

用法:

>>> import dateparser
>>> dateparser.parse('2 minutes ago')
datetime.datetime(2018, 11, 27, 13, 44, 54, 993170)
>>> dateparser.parse('yesterday at 15:12')
datetime.datetime(2018, 11, 26, 15, 12)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM