datetime from string in Python, best-guessing string format

后端 未结 4 1742
后悔当初
后悔当初 2020-11-27 15:33

The function to get a datetime from a string, datetime.strptime(date_string, format) requires a string format as the second argument. Is there a way to build a

4条回答
  •  萌比男神i
    2020-11-27 15:49

    You can use datefinder ,It will detect all types of natural style of dates.

    import datefinder # Module used to find different style of date with time

    string_value = " created 01/15/2005 by ACME inc.and associates.January 4th,2017 at 8pm"
    matches = datefinder.find_dates(string_value)            
    for match in matches:
        print("match found ",match)
    

    Output

    match found  2005-01-15 00:00:00
    match found  2017-01-04 20:00:00
    

提交回复
热议问题