V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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
kenneth
V2EX  ›  Python

关于时间格式的问题。

  •  
  •   kenneth · Dec 23, 2012 · 4573 views
    This topic created in 4875 days ago, the information mentioned may be changed or developed.
    用jinja2显示
    datetime.datetime.now()
    为什么时间秒还有小数点
    2012-12-23 23:37:21.392117
    求释疑。
    3 replies    1970-01-01 08:00:00 +08:00
    LTS
        1
    LTS  
       Dec 23, 2012 via iPhone
    毫秒。
    aulara
        2
    aulara  
       Dec 24, 2012
    用strptime就解决啦
    BOYPT
        3
    BOYPT  
       Dec 25, 2012   ❤️ 1
    这问的也真够奇怪的,datetime本来就存储了到那个精度的时间数值,那显示小数不是很应该的么

    如果你需要按自己需求显示时间格式,那应该使用使用格式化了的时间,strftime,也可以给jinja2添加个filter,这样在模板里面的代码就干净利落了, 如: http://stackoverflow.com/questions/4830535/python-how-do-i-format-a-date-in-jinja2

    @aulara strptime是从字符串解析出时间(parse),strftime是时间变成字符串(format)
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5537 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 03:10 · PVG 11:10 · LAX 20:10 · JFK 23:10
    ♥ Do have faith in what you're doing.