Python pytz timezone function returns a timezone that is off by 9 minutes

后端 未结 4 1527
一整个雨季
一整个雨季 2020-12-09 08:00

For some reason which I haven\'t been able to figure out yet, from the the following code:

>>> from pytz import timezone
>>> timezone(\'Ame         


        
4条回答
  •  南方客
    南方客 (楼主)
    2020-12-09 08:08

    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.

    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'
    

    See

    • Datetime Timezone conversion using pytz
    • pytz localize vs datetime replace

    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.

提交回复
热议问题