有没有人可以帮助我了解这里发生了什么?
import pytz
from datetime import datetime
tz = pytz.timezone('Europe/Berlin')
print repr(tz)
# <DstTzInfo 'Europe/Berlin' LMT+0:53:00 STD>
dt = datetime(2011, 1, 3, 18, 40)
result = tz.localize(dt)
print repr(result.tzinfo)
# <DstTzInfo 'Europe/Berlin' CET+1:00:00 STD>
assert result.tzinfo == tz, "Why aren't these the same timezone?"
我的理解是,localize()
pytz 时区对象上的方法将采用一个简单的日期时间对象,并添加一个tzinfo
与执行本地化的时区对象相匹配的属性。在这种情况下,这似乎没有发生。
显然,我对时区或 pytz 处理时区的方式有一些误解。谁能解释一下?