Python - finding date in a string

前端 未结 5 1960
误落风尘
误落风尘 2021-02-20 12:24

I want to be able to read a string and return the first date appears in it. Is there a ready module that I can use? I tried to write regexs for all possible date format, but it

5条回答
  •  忘掉有多难
    2021-02-20 12:54

    I found the following very useful for converting the time to a uniform format and then searching for this format pattern:

    from datetime import datetime

    date_object = datetime.strptime('March-1-05', '%B-%d-%y')
    print date_object.strftime("%B %d, %Y")

提交回复
热议问题