Python module to extract probable dates from strings?

前端 未结 2 1570
野趣味
野趣味 2021-02-05 15:51

I\'m looking for a Python module that would take an arbitrary block of text, search it for something that looks like a date string, and build a DateTime object out of it. Somet

2条回答
  •  失恋的感觉
    2021-02-05 16:33

    The nearest equivalent is probably the dateutil module. Usage is:

    >>> from dateutil.parser import parse
    >>> parse("Wed, Nov 12")
    datetime.datetime(2008, 11, 12, 0, 0)
    

    Using the fuzzy parameter should ignore extraneous text. ie

    >>> parse("the date was the 1st of December 2006 2:30pm", fuzzy=True)
    datetime.datetime(2006, 12, 1, 14, 30)
    

提交回复
热议问题