It would do the helpful for converting string to datetime and also with time zone
def convert_string_to_time(date_string, timezone): from datetime import datetime import pytz date_time_obj = datetime.strptime(date_string[:26], '%Y-%m-%d %H:%M:%S.%f') date_time_obj_timezone = pytz.timezone(timezone).localize(date_time_obj) return date_time_obj_timezonedate = '2018-08-14 13:09:24.543953+00:00'TIME_ZONE = 'UTC'date_time_obj_timezone = convert_string_to_time(date, TIME_ZONE)