为何Europe/Berlin时区会出现+00:53偏移?代码差异解析
t1 Show a +00:53 Offset for Berlin? Sample Code
from datetime import datetime, timezone import pytz tzstring = 'Europe/Berlin' t1 = datetime(2016, 6, 16, 2, 0, tzinfo=pytz.timezone(tzstring)) t2 = datetime(2016, 6, 16, 2, 0, tzinfo=timezone.utc).astimezone(pytz.timezone(tzstring))
Actual Output
print(t1): 2016-06-16 02:00:00+00:53 print(t2): 2016-06-16 04:00:00+02:00
Expected Output
print(t1): 2016-06-16 04:00:00+02:00 # 不符合预期 (Not as expected) print(t2): 2016-06-16 04:00:00+02:00 # 符合预期 (As expected)
Great question! That odd +00:53 offset in t1 isn't a bug—it's a window into the history of timekeeping in Berlin. Here's the breakdown:
When you pass pytz.timezone('Europe/Berlin') directly to the datetime constructor's tzinfo parameter, you're not getting the modern Central European Time (CET/CEST) rules you expect. Instead, pytz returns the local mean time (LMT) that Berlin used before standardized time zones existed.
Back in the 1800s, before railroads and global communication made synchronized time necessary, every city set their clocks based on their own local solar time. Berlin sits at longitude 13°23'30" east of the Prime Meridian in Greenwich. Since each degree of longitude corresponds to 4 minutes of time difference (360 degrees = 24 hours), Berlin's local mean time works out to roughly 53 minutes and 28 seconds ahead of UTC—hence the +00:53 offset in your output.
Berlin didn't switch to a standardized time zone (UTC+1, later CET) until 1893, as part of a broader push across Europe to align time for rail travel and commerce. Today, Europe/Berlin follows rules that include daylight saving time (shifting to UTC+2 in summer, like in June 2016 when your example runs).
When you use astimezone() (like in t2) or pytz's localize() method, you're telling pytz to apply the full timezone database rules for Europe/Berlin. This database includes all historical changes—from the switch from LMT to CET, to subsequent adjustments for daylight saving time. That's why t2 correctly shows the UTC+2 offset for CEST in June 2016.
To recap:
- Directly using a pytz timezone in
datetime'stzinfogives you the raw local mean time for the city's longitude, not modern timezone rules. - Use
astimezone()orpytz.localize()to get the correct historical/current timezone offsets you need.
内容的提问来源于Stack Exchange,提问作者Martin Thoma

