使用 pytz 时区与时区字符串替换时区时的奇怪行为

Weird behavior on when replacing timezone using pytz timezones vs timezone strings

我希望使用 'US/Central' 替换 tzinfo 会得到与使用时区对象 (pytz.timezone('US/Central')) 相同的结果,但显然不是:

In [5]: import arrow
In [6]: d = arrow.get()
In [7]: cst = pytz.timezone('US/Central')

In [8]: d.replace(tzinfo=cst)
Out[8]: <Arrow [2015-07-22T17:40:30.947579-06:00]>

In [9]: d.replace(tzinfo='US/Central')
Out[9]: <Arrow [2015-07-22T17:40:30.947579-05:00]>

请注意第 8 行的输出与第 9 行的输出有何不同的 UTC 偏移量。

使用 Arrow 和 pytz 替换时区的正确方法是什么?

这似乎是一个错误。我猜你看到的是 issue 154 -

.to() is incompatible with pytz.timezone

对于 .replace() 方法,您可能会看到同样的情况。该问题仍未解决。

我会说使用箭头一,似乎目前箭头和 pytz 不兼容。