python datetime strptime wildcard

前端 未结 5 2018
有刺的猬
有刺的猬 2021-01-04 02:23

I want to parse dates like these into a datetime object:

  • December 12th, 2008
  • January 1st, 2009

The following will work for the first d

5条回答
  •  旧时难觅i
    2021-01-04 02:53

    Try using the dateutil.parser module.

    import dateutil.parser
    date1 = dateutil.parser.parse("December 12th, 2008")
    date2 = dateutil.parser.parse("January 1st, 2009")
    

    Additional documentation can be found here: http://labix.org/python-dateutil

提交回复
热议问题