datetime and timezone conversion with pytz - mind blowing behaviour
我正在尝试将时区感知的
1 2 3 4 | t = datetime( 2013, 11, 22, hour=11, minute=0, tzinfo=pytz.timezone('Europe/Warsaw') ) |
现在在伊普敦:
1 2 3 4 | In [18]: t Out[18]: datetime.datetime( 2013, 11, 22, 11, 0, tzinfo=<DstTzInfo 'Europe/Warsaw' WMT+1:24:00 STD> ) |
号
现在让我们试着转换到UTC然后返回。我希望有与以下内容相同的陈述:
1 2 3 4 | In [19]: t.astimezone(pytz.utc).astimezone(pytz.timezone('Europe/Warsaw')) Out[19]: datetime.datetime( 2013, 11, 22, 10, 36, tzinfo=<DstTzInfo 'Europe/Warsaw' CET+1:00:00 STD> ) |
然而,我们发现
the documentation http:///美国"不幸的是他/她pytz.sourceforge.net using the argument of the tzinfo does not work是标准的DateTime constructors与pytz for many时区的尾巴。"P></
1 2 3 4 | t = datetime( 2013, 5, 11, hour=11, minute=0, tzinfo=pytz.timezone('Europe/Warsaw') ) |
根据这一不工作,而不是使用方法:localize You should theP></
1 2 | t = pytz.timezone('Europe/Warsaw').localize( datetime(2013, 5, 11, hour=11, minute=0)) |