Why a timezone aware datetime's tzinfo does not equal the timezone?

后端 未结 2 1600
北荒
北荒 2021-01-19 13:00
>>> import pytz
>>> tz = pytz.timezone(\'America/Chicago\')
>>> dt_naive = datetime(year=2017, month=6, day=6)
>>> dt_aware = tz.         


        
2条回答
  •  灰色年华
    2021-01-19 13:29

    The first one has been adjusted to the date and time provided, 2016-06-06T00:00:00. Central Daylight Time (CDT) is in effect at this time. It is 5 hours behind UTC (24:00 - 05:00 = 19:00).

    The second one has not been localized, so it is giving you the first offset in the available time zone data, which happens to be the Local Mean Time (LMT) entry. You can see this in the tzdata sources here. The LMT is 5 hours, 50 minutes, and 36 seconds behind UTC. The seconds of the LMT offset are rounded off somewhere in pytz, so 18:09 is reflecting this correctly (24:00 - 05:51 = 18:09)

提交回复
热议问题