出于某种我还没有弄清楚的原因,从以下代码中:
For some reason which I haven't been able to figure out yet, from the the following code:
>>> from pytz import timezone
>>> timezone('America/Chicago')
我明白了:
<DstTzInfo 'America/Chicago' LMT-1 day, 18:09:00 STD>
什么时候,我想,我应该得到:
When, I assume, I should get:
<DstTzInfo 'America/Chicago' LMT-1 day, 18:00:00 STD>
...因为我不认为我的时区与 UTC 相差 6 小时 9 分钟.
...since I don't think that my timezone is 6 hours and 9 minutes away from UTC.
我查看了 pytz
的源代码,但我承认我还没有完全弄清楚出了什么问题.
I have looked at the source code for pytz
but I will admit that I haven't exactly been able to figure out what is going wrong.
我已将其他值传递给 timezone()
函数,它返回的值似乎是正确的.但由于某种原因,与我的时区相关的信息不正确.
I have passed other values to the timezone()
function, and the values it returns appear to be correct. For some reason though, the information relevant to my timezone is not correct.
最后,我旁边立方体中的同事确认该函数在他的机器上返回了正确的时区信息.
Finally, my co-worker in the cube next to me has confirmed that the function returns the correct timezone info on his machine.
有人知道为什么我的时区('America/Chicago'
)会延迟 9 分钟吗?我正在运行使用 pip
安装的 pytz
版本 2015.7
.谢谢!
Does anyone have any idea why my timezone ('America/Chicago'
) would be off by 9 minutes? I am running version 2015.7
of pytz
installed using pip
. Thank you!
除非您的本地时区有固定的 UTC 偏移量,否则在不提供具体日期/时间的情况下谈论其具体值是没有意义的.
Unless your local timezone has a fixed UTC offset then it is pointless to talk about its specific value without providing a specific date/time.
如果您提供时间,例如当前时间,那么您将看到 pytz
产生预期的 UTC 偏移量:
If you provide the time e.g., the current time then you'll see that pytz
produces the expected UTC offset:
>>> from datetime import datetime
>>> import pytz
>>> datetime.now(pytz.timezone('America/Chicago')).strftime('%Z%z')
'CST-0600'
见
如果您不提供特定的日期/时间,则 pytz
可能会从给定时区的可用 utc 偏移量集中返回任意 utc 偏移量.最近的 pytz
版本返回对应于最早时间(通常为 LMT)的 utc 偏移量,但您不应依赖它.您和您的朋友可能使用不同的 pytz 版本,这可能会解释结果的差异.
If you don't provide a specific date/time then pytz
may return an arbitrary utc offset from the set of available utc offsets for the given timezone. The recent pytz
versions return utc offsets that correspond to the earliest time (LMT as a rule) but you should not rely on it. You and your friend may use different pytz versions that may explain the difference in results.
这篇关于Python pytz 时区函数返回一个相差 9 分钟的时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!