I have a date time say 06-07-2021 11:59:00 (mm-dd-yyyy HH:MM:SS) which is time in EST. This time need to be changed directly to UTC.
To be noted that EST follows Day light saving whereas UTC would not.
I have a date time say 06-07-2021 11:59:00 (mm-dd-yyyy HH:MM:SS) which is time in EST. This time need to be changed directly to UTC.
To be noted that EST follows Day light saving whereas UTC would not.
from datetime import datetime, timedelta, timezone
import time
# make datetime from timestamp, thus no timezone info is attached
now = datetime.fromtimestamp(time.time())
# make local timezone with time.timezone
local_tz = timezone(timedelta(seconds=-time.timezone))
# attach different timezones as you wish
utc_time = now.astimezone(timezone.utc)
local_time = now.astimezone(local_tz)
print(utc_time.isoformat(timespec='seconds'))
print(local_time.isoformat(timespec='seconds'))