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
SP00F
V2EX  ›  Python

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

  •  
  •   SP00F · 2017-03-12 19:19:43 +08:00 · 1725 次点击
    这是一个创建于 2608 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

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

    5 条回复    2017-03-14 22:02:37 +08:00
    skysword
        1
    skysword  
       2017-03-12 22:54:15 +08:00 via Android
    储存为 timestamp 更合适吧
    julyclyde
        2
    julyclyde  
       2017-03-12 22:58:54 +08:00   ❤️ 2
    存储用 utc 、展现用当地时区是金科玉律
    timestamp 不能处理闰秒
    skysword
        3
    skysword  
       2017-03-12 23:04:07 +08:00 via Android
    @julyclyde 多谢,学习了,之前想当然了
    SP00F
        4
    SP00F  
    OP
       2017-03-12 23:36:34 +08:00
    @julyclyde
    @skysword
    大概是以 Unix 时间戳更便利吧? thx
    julyclyde
        5
    julyclyde  
       2017-03-14 22:02:37 +08:00
    @SP00F no
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1746 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 00:32 · PVG 08:32 · LAX 17:32 · JFK 20:32
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.