Why doesn't pytz localize() produce a datetime object with tzinfo matching the tz object that localized it?

前端 未结 1 579
臣服心动
臣服心动 2020-12-10 14:08

Is there anyone who can help me understand what\'s going on here?

import pytz
from datetime import datetime
tz = pytz.timezone(\'Europe/Berlin\')
print repr(         


        
相关标签:
1条回答
  • 2020-12-10 14:37

    They are the same time zone - "Europe/Berlin".

    When you are printing them, the output includes the abbreviation and offset that applies at that particular point in time.

    If you examine the tz data sources, you'll see:

    # Zone  NAME            GMTOFF   RULES       FORMAT   [UNTIL]
    Zone    Europe/Berlin   0:53:28  -           LMT      1893 Apr
                            1:00     C-Eur       CE%sT    1945 May 24 2:00
                            1:00     SovietZone  CE%sT    1946
                            1:00     Germany     CE%sT    1980
                            1:00     EU          CE%sT
    

    So it would appear that when the time zone has not localized a datetime, then it just uses the first entry.

    It would also appear that pytz doesn't retain the extra 28 seconds from the original local mean time deviation - but that doesn't matter unless you are working with dates in Berlin before April 1893.

    0 讨论(0)
提交回复
热议问题