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

[求助] 后台保存的是 UTC 时间,前端如何转换成 user 时区的时间?

  •  
  •   hustlzp · Nov 18, 2014 · 5208 views
    This topic created in 4222 days ago, the information mentioned may be changed or developed.
    RT.

    是不是需要在前端判断用户的时区,然后再将后端输出的UTC时间转换过来?

    求教。
    Supplement 1  ·  Nov 18, 2014
    在前端首先通过Date对象的getTimezoneOffset获取偏移值,然后用moment.js进行日期运算就OK了。
    2 replies    2014-11-18 12:14:05 +08:00
    rankjie
        1
    rankjie  
       Nov 18, 2014
    Date有个方法是 toLocaleString

    会自动转成对应访问者浏览器语言、时区的字符串

    另外还有 toLocaleDateString, toLocaleTimeString 可供使用
    hustlzp
        2
    hustlzp  
    OP
       Nov 18, 2014
    @rankjie 谢谢。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5378 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 06:51 · PVG 14:51 · LAX 23:51 · JFK 02:51
    ♥ Do have faith in what you're doing.