Question is as simple as:
I have a timestamp = Apr 23, 2024 4:55:12 AM EDT.
I want to convert this into UTC/GMT.
I havent been able to find a solution for this anywhere. I could not find any support for abbreviations in datetime, dateutil, pytz or zoneinfo.
The following fails due to format error
dt_var = datetime.strptime(my_timestamp, '%b %d, %Y %I:%M:%S %p %Z')
The only solution i could find is do something like
dt_var = datetime.strptime(my_timestamp[:-4], '%b %d, %Y %I:%M:%S %p')
timezone_abbr = my_timestamp[-3:]
timezone = pytz.timezone(timezone_mapping[timezone_abbr])
dt_localized = timezone.localize(dt_var)
dt_gmt = dt_localized.astimezone(pytz.utc)
where timezone_mapping is:
timezone_mapping = {
"EDT": "America/New_York"
}
But I dont want to store a map like this. Anyways 1 shortform could correspond to multiple regions.
Is there any library i can use in python that can read the timezone abbreviation and convert it to gmt.