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

有没有什么优雅或者一行 格式化时间为年月日的方法(月份小于 10 的情况)

  •  
  •   pppy · Mar 22, 2017 · 2983 views
    This topic created in 3339 days ago, the information mentioned may be changed or developed.
    datetime.now().strftime('%m月%d日%H点')
    
    03月22日12点
    

    月份前面会有 0

    6 replies    2017-04-01 17:31:45 +08:00
    billgreen1
        1
    billgreen1  
       Mar 22, 2017
    datetime.now().strftime('%-m 月%d 日%H 点')
    billgreen1
        2
    billgreen1  
       Mar 22, 2017   ❤️ 1
    "{dt.month}月{dt.day}日{dt.hour}点".format(dt=datetime.datetime.now())
    pppy
        3
    pppy  
    OP
       Mar 22, 2017
    ausdruck
        4
    ausdruck  
       Mar 22, 2017
    echo date('Y 年 m 月 d 日', time()).' 乱入 php 是世界上最好的语言';
    xray887
        5
    xray887  
       Mar 22, 2017
    AttributeError: module 'datetime' has no attribute 'now'
    Yingruoyuan
        6
    Yingruoyuan  
       Apr 1, 2017
    @xray887 ,用改导入为 from datetime import datetime
    或者 datetime.datetime.now().strftime('%-m 月%d 日%H 点')试试
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5986 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 64ms · UTC 02:50 · PVG 10:50 · LAX 19:50 · JFK 22:50
    ♥ Do have faith in what you're doing.