How to parse a String into Datetime in Python


Wed Jan 22 2020 18:52:28 GMT+0000 (Coordinated Universal Time)

Saved by @logicloss01 #python #dates #functions #python3.8

from datetime import datetime

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

Resulting object is in native time zone of user. ValueError is raised if the date_string and format can’t be parsed by time.strptime() or if it returns a value which isn’t a time tuple.