Reputation: 181
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:')
Upvotes: 0
Views: 520
Reputation: 2178
from dateutil import parser
print (parser.parse("May 29 13:40:06 CDT 2018"))
Output
2018-05-29 13:40:06
Reference: python-dateutil
Upvotes: 1
Reputation: 6058
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'
Upvotes: 1