How to parse a datetime object with timezone information from a date string in Python

Changing a date string containing information about a date, time, and timezone changes the object’s type from a string to a datetime object. For example, “Wed Jan 1 00:00:00 EST 2020” as a date string is 2020-01-01 00:00:00-05:00 as a datetime object.

Solution for How to parse a datetime object with timezone information from a date string in Python : You can use dateutil.tz.gettz() and dateutil.parser.parse() to parse a datetime object with timezone information from a date string Define a dictionary dict with the desired timezone abbreviation as the key. Call dateutil.tz.gettz(timezone_string) with timezone_string as a string representation of the desired timezone to get a timezone object as the key’s corresponding value. Call dateutil.parser.parse(date_string, tzinfos=dict) with date_string as the string containing the date, time, and timezone information.


how-to-parse-a-datetime-object-with-timezone-information-from-a-date-string-in-python