Find Monday's date with Python

前端 未结 8 2033
被撕碎了的回忆
被撕碎了的回忆 2020-12-13 03:22

How do I find the previous Monday\'s date, based off of the current date using Python? I thought maybe I could use: datetime.weekday() to do it, but I am gettin

8条回答
  •  误落风尘
    2020-12-13 03:56

    You can use Natty. I tried parsedatetime and dateparser. Comparing these three, I think Natty is the best one.

    To get your result, use like this:

    >>> from natty import DateParser
    >>> dp = DateParser('last monday')
    >>> dp.result()
    [datetime.datetime(2016, 8, 1, 17, 35, 5, tzinfo=tzlocal())] #Today is 9th of August 2016 5.35 PM
    

    Github Link : https://github.com/eadmundo/python-natty

    Try it, It can do more!

提交回复
热议问题