Search code examples
pythondatetimetimezoneunix-timestamppytz

Python3.7 datetime.timestamp() returns a wrong value by two minutes (???)


If I have this code:

import datetime
import pytz

dt = datetime.datetime(
    year=2021,
    month=3,
    day=3,
    hour=11,
    minute=30,
    second=15,
    microsecond=0,
    tzinfo=pytz.timezone("Europe/Prague")
)

Then this is the result of dt.timestamp():

1614767535.0

Which translates to Wed Mar 03 2021 10:32:15 GMT+0000 while I would expect 10:30:15 instead.

What's the deal here?


Solution

  • The problem is caused by tzinfo=pytz.timezone("Europe/Prague")

    Explanation is here: Python pytz timezone function returns a timezone that is off by 9 minutes