【发布时间】:2018-10-30 18:47:43
【问题描述】:
示例代码
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))
观察到
print(t1): 2016-06-16 02:00:00+00:53
print(t2): 2016-06-16 04:00:00+02:00
预期
print(t1): 2016-06-16 04:00:00+02:00 # does not match expectation
print(t2): 2016-06-16 04:00:00+02:00 # matches expectation
问题
谁能给我解释一下?
其他问题:
- Why doesn't pytz localize() produce a datetime object with tzinfo matching the tz object that localized it? 只要求解释“代码的来源”。我的问题更偏向于:“为什么会这样?” - 我接受的答案很可能会包含一些历史。
【问题讨论】:
-
另一个答案也说明了为什么它是这个值:LMT。在这么简单的问题中,我真的没有看到大节标题的好处。
-
这样的原因并不是真正的编程问题。它与history of german timezones有关。
-
@SeanBreckenridge 啊,太好了! This Wiki article 朝着正确的方向前进!我仍然想念的是当地时间是如何计算的。
标签: python python-3.x datetime timezone pytz