Parse French date in python

后端 未结 3 949
耶瑟儿~
耶瑟儿~ 2020-12-03 17:38

Can someone please tell me how can I parse a French date in Python? Sorry if the question is a duplicate but I couldn\'t find one.

Here is what I have tried using t

3条回答
  •  情深已故
    2020-12-03 18:11

    dateparser module can parse dates in the question:

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    import dateparser # $ pip install dateparser
    
    for date_string in [u"Aujourd'hui", "3 juillet", u"4 Août", u"Hier"]:
        print(dateparser.parse(date_string).date())
    

    It translates dates to English using a simple yaml config and passes the date strings to dateutil.parser.

    Output

    2015-09-09
    2015-07-03
    2015-08-04
    2015-09-08
    

提交回复
热议问题