I am finding a very strange behavior for different timezones in Python. The following code:
import datetime as dtm
import pytz
def test_tz():
america_ny_tz: dtm.tzinfo = pytz.timezone("America/New_York")
est_tz: dtm.tzinfo = pytz.timezone("EST5EDT")
today = dtm.date.today()
ny_dtm = dtm.datetime(
year=today.year, month=today.month, day=today.day, tzinfo=america_ny_tz
)
est_dtm = dtm.datetime(
year=today.year, month=today.month, day=today.day, tzinfo=est_tz
)
print(f"New York: {ny_dtm.timestamp()}, EST: {est_dtm.timestamp()}")
if __name__ == "__main__":
test_tz()
outputs:
New York: 1609995360.0, EST: 1609995600.0
As you may notice the difference is about 4 minutes where one would have to assume the time should be the same.
Am I accessing Time Zone information incorrectly or is my understanding that the Time Zone information should be the same?
Running on Linux, Ubuntu 20.04 but the behavior on 18.04 was the same.
P.S. I haven't tried other languages or different OS' to see if the behavior will be the same.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…