Search code examples
pythonpython-datetime

Converting String Date to DateTime in python where String format is YYYY-MM-DD Hr-Min-Sec in python


from datetime import datetime
datetime_object = datetime.strptime('Jun 1 2005  1:33PM', '%b %d %Y %I:%M%p')

This Date time conversion works, but the input format is a bit different.

dateTimeStr="2018-09-28 14:38:41+00:00"

or dateTimeStr="2018-09-28 14:38:41"

Looking for some code like

datetime_object = datetime.strptime('2018-09-28 14:38:41','%YYYY-%MM-%DD %I:%M:%S)


Solution

  • So it works:

    datetime_object = datetime.strptime('2018-09-28 14:38:41','%Y-%m-%d %H:%M:%S')