Search code examples
pythondatetimetimezonepytz

timezone conversion in Python


I'm probably missing something about timezones:

>>> import datetime, pytz
>>> date = datetime.datetime(2013,9,3,16,0, tzinfo=pytz.timezone("Europe/Paris"))
>>> date.astimezone(pytz.UTC)
datetime.datetime(2013, 9, 3, 15, 51, tzinfo=<UTC>)

I was expecting

datetime.datetime(2013, 9, 3, 15, 00, tzinfo=<UTC>)

Can anyone explain me where these 51 minutes come from?

Thanks,

Jean-Philippe


Solution

  • The UTC offset gives (date.tzinfo.utcoffset(date)):

    datetime.timedelta(0, 540)
    

    This is 540 seconds or 9 minutes.

    In France the switch to UTC was made on March 11, 1911 and the clocks were turned back 9 minutes and 21 seconds (source 1, source 2):

    Until 1911, Paris was 9 minutes and 21 seconds off UTC.

    You can also see it here (Paris time in 1911) where the time goes from March 11, 12:01:00 AM to March 10, 11:51:39 PM.