I am US/Pacific timezone (and my devices are too).
import time
import pytz
from datetime import datetime
from datetime import timezone
from zoneinfo import ZoneInfo
tz_pac = pytz.timezone('US/Pacific')
dt_pac = tz_pac.localize(datetime(2024, 2, 25))
print(dt_pac)
# datetime.datetime(2024, 2, 25, 0, 0, tzinfo=<DstTzInfo 'US/Pacific' PST-1 day, 16:00:00 STD>)
epoch_pac = int(dt_pac.strftime('%s'))
print(epoch_pac)
# 1708848000
Yes, this is correct.
tz_est = pytz.timezone('US/Eastern')
dt_est = tz_est.normalize(dt_pac)
print(dt_est)
datetime.datetime(2024, 2, 25, 3, 0, tzinfo=<DstTzInfo 'US/Eastern' EST-1 day, 19:00:00 STD>)
Yes, it was 3:00 am in the Eastern timezone, when it was midnight Pacific timezone.
print(int(dt_est.strftime('%s')))
# 1708858800
So why are the epochs different?
tried searching and tried to figure it out myself…
NOTE: Please don’t use datetime.now()
, I need to convert certain times that are not right now. Thank you!