2 points

How to parse a String into Datetime in Python


Wed Jan 22 2020 18:52:28 GMT+0000 (UTC)

Posted 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')
content_copy Copy

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.