Converting a time string without UTC with reducing the time interval to UTC time in python, while accounting for daylight saving time

I find it difficult to convert a string representation of non-UTC time to UTC due to the shortening of the time zone paragraph.

(update: it seems that time zone abbreviations may not be unique . If so, maybe I should also consider this. )

I am trying to find a way around this using datetutil and pytz, but no luck.

Suggestions or workarounds are welcome.

string = "Jun 20, 4:00PM EDT" 

I would like to convert this to UTC, while taking into account the daily savings.

UPDATE: Find some links that may help more experienced users answer question Q.

In fact, I would have imagined part of a solution doing the other side of this .

FINAL UPDATE (IMPORTANT)

Adapted from dateutil docs examples .

Some simple examples based on the date command, using the TZOFFSET dictionary to provide BRST timeline offset.

  

parse ("Thu Sep 25 10:36:28 BRST 2003", tzinfos = TZOFFSETS) datetime.datetime (2003, 9, 25, 10, 36, 28, tzinfo = tzoffset ('BRST', -10800))

         

parse ("2003 10:36:28 BRST 25 Sep Thu", tzinfos = TZOFFSETS) datetime.datetime (2003, 9, 25, 10, 36, 28, tzinfo = tzoffset ('BRST', -10800))

  

Combine this with a library, for example, found here. and you will have a solution to this problem.

+5
1

Nas Banov UTC offset:

import dateutil
import pytz

# timezone dictionary built here: /questions/17829/parsing-datetime-string-with-timezone-abbreviated-name-in-python/131308#131308
# tzd = {...}

string = 'Jun 20, 4:00PM EDT'
date = dateutil.parser.parse(string, tzinfos=tzd).astimezone(pytz.utc)
+5

All Articles