0

I went through datetime python page, and other related pages, but unable to get this thing to work.

I have the following string that I want to convert to python date object.

May 29, 2018 10:40:06 CDT AM:

I use the following to match, but python2.7 is giving me doesnt match error.

datetime_object = datetime.strptime(line, '%B %d, %Y %I:%M:%S %Z %p:')
  • Try: https://stackoverflow.com/questions/24064906/how-to-convert-thu-jun-5-105910-cdt-2014-into-python-datetime-object – Rakesh Jun 05 '18 at 16:15

2 Answers2

1

It seems as though CDT is not a valid timezone name as it works with GMT.

>>> str(datetime.strptime('May 29, 2018 10:40:06 GMT AM:', '%B %d, %Y %I:%M:%S %Z %p:'))
'2018-05-29 10:40:06'
Jim Wright
  • 5,905
  • 1
  • 15
  • 34
1
from dateutil import parser
print (parser.parse("May 29 13:40:06  CDT 2018"))

Output

2018-05-29 13:40:06

Reference: python-dateutil

Roshan Bagdiya
  • 2,048
  • 21
  • 41