推荐学习书目
› 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
SP00F
V2EX  ›  Python

Python 时区东夏令时处理有更优雅的方法吗?

  •  
  •   SP00F · Mar 12, 2017 · 2575 views
    This topic created in 3484 days ago, the information mentioned may be changed or developed.

    场景:采集加拿大过来的数据是加拿大的时区,加拿大每年会有东夏令时切换。抓取到的数据存储到数据库时是以北京时间存储的。但是每次到了东夏令时的切换,会导致插入的时间少了一个小时或者多一个小时。

    假设将采集的数据转为 UTC 存储到数据库中,在取数据时转换为当地时间是不是更为妥当一些?

    5 replies  •  2017-03-14 22:02:37 +08:00
    skysword
        1
    skysword  
       Mar 12, 2017 via Android
    储存为 timestamp 更合适吧
    julyclyde
        2
    julyclyde  
       Mar 12, 2017   ❤️ 2
    存储用 utc 、展现用当地时区是金科玉律
    timestamp 不能处理闰秒
    skysword
        3
    skysword  
       Mar 12, 2017 via Android
    @julyclyde 多谢,学习了,之前想当然了
    SP00F
        4
    SP00F  
    OP
       Mar 12, 2017
    @julyclyde
    @skysword
    大概是以 Unix 时间戳更便利吧? thx
    julyclyde
        5
    julyclyde  
       Mar 14, 2017
    @SP00F no
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2823 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 03:31 · PVG 11:31 · LAX 20:31 · JFK 23:31
    ♥ Do have faith in what you're doing.