I am trying to identify the timestamp of a specific moment in time, considering a particular date and time with a particular timezone.
However, it seems that constructing that combination with datetime.combine()
will give me one result, while using datetime.now().replace()
will give me another one.
from datetime import datetime, time
import pytz
ny_tz = pytz.timezone('America/New_York')
datetime.combine(datetime.today(), time(15, 54, 55), tzinfo=ny_tz).timestamp()
# 1648846255.0
datetime.now(tz=ny_tz).replace(hour=15, minute=54, second=55, microsecond=0).timestamp()
# 1648842895.0
The datetime.combine()
option seems to give me a timeframe that is about 56-minutes off.
What's the reason behind this difference?
Edit: As requested in the comments, the usage of pytz.timezone.localize
also fails:
ny_tz.localize(datetime.combine(datetime.today(), time(15, 54, 55))).timestamp()
# 1648842895.0