0

I am having trouble converting a string date to UTC.

from datetime import datetime as dt2
import pytz

fmt_str: str = "%Y-%m-%d %H:%M:%S"
email_date = "2023-05-24 16:12:00"

est_tz = pytz.timezone("US/Eastern")
america_tz = pytz.timezone("America/New_York")

est_dt_obj = dt2.strptime(email_date, '%Y-%m-%d %H:%M:%S').replace(tzinfo=est_tz)
america_dt_obj = dt2.strptime(email_date, '%Y-%m-%d %H:%M:%S').replace(tzinfo=america_tz)

print(est_dt_obj)
## prints 2023-05-24 16:12:00-04:56

print(america_dt_obj)
## prints 2023-05-24 16:12:00-04:56

The email_date I receive is always in EST/EDT so I am trying to assign that timezone to the date. However its doing the incorrect offset for UTC. My end goal is to covert that time to UTC before saving it into the database but the offset should be -4 not -5 currently. Am I doing the timezone incorrectly?

The only other solution I have is to check if I'm in daylight savings based on the date then use the timezone ETC/GMT+4 or ETC/GMT+5

0 Answers0