V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
Qzier
V2EX  ›  Python

慎用 pytz 模块,中国时区有偏差!

  •  
  •   Qzier · 2020-08-10 21:25:50 +08:00 · 2016 次点击
    这是一个创建于 1326 天前的主题,其中的信息可能已经有所发展或是发生改变。

    pytz 中的上海时区或者 PRC 时区,不是我们常用的 8 小时偏移,而是 8 小时 6 分,导致我转换时间出现了偏差。

    pytz.timezone('PRC')
    Out[195]: <DstTzInfo 'PRC' LMT+8:06:00 STD>
    
    pytz.timezone('Asia/Shanghai')
    Out[196]: <DstTzInfo 'Asia/Shanghai' LMT+8:06:00 STD>
    
    5 条回复    2020-08-31 17:46:39 +08:00
    Qzier
        1
    Qzier  
    OP
       2020-08-10 21:47:22 +08:00
    经测试,dateutil 没有这个问题,它的中国时区就是 8 小时整的便移量来算的。
    julyclyde
        2
    julyclyde  
       2020-08-11 10:53:04 +08:00
    这个问题随便搜搜就知道是你用错了啊
    Qzier
        3
    Qzier  
    OP
       2020-08-11 16:19:55 +08:00
    @julyclyde 这是 pytz 的坑,dateutil 就没有这个问题。
    neoblackcap
        4
    neoblackcap  
       2020-08-30 05:57:47 +08:00
    @Qzier 用用搜索引擎你就知道是你自己的问题
    Qzier
        5
    Qzier  
    OP
       2020-08-31 17:46:39 +08:00 via iPhone
    @neoblackcap 用谷歌搜一下就知道不少人发现了这个 bug
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5359 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 07:58 · PVG 15:58 · LAX 00:58 · JFK 03:58
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.