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

django 的 时间过滤器 | 输出如下格式的时间: 2020-03-18T09:55:47

  •  
  •   python30 · 2020-03-19 17:14:00 +08:00 · 1516 次点击
    这是一个创建于 1504 天前的主题,其中的信息可能已经有所发展或是发生改变。
    django 的 时间过滤器 | 输出如下格式的时间:2020-03-18T09:55:47

    代码: {{pubdate|date:"Y-m-dTH:i:s"}} 怎么成了: 2020-03-18CST09:55:47

    这个 T 自动转换成 CST 了

    怎么把这个时间换成 2020-03-18T09:55:47 格式?
    5 条回复    2020-03-19 17:28:51 +08:00
    wuwukai007
        1
    wuwukai007  
       2020-03-19 17:21:54 +08:00
    转义了 \T
    T 表示本机所在的时区
    Hstar
        3
    Hstar  
       2020-03-19 17:25:02 +08:00
    看看文档 https://docs.djangoproject.com/en/3.0/ref/templates/builtins/#date , 说得蛮清楚了

    这字符串会被当做正则处理,T 也是一个关键词,所以要写成 Y-m-d\TH:i:s
    janxin
        4
    janxin  
       2020-03-19 17:26:34 +08:00
    因为 T 是有意义的,表示 TimeZone...

    你在这里面试试就可以了

    https://docs.djangoproject.com/en/3.0/ref/templates/builtins/#date
    python30
        5
    python30  
    OP
       2020-03-19 17:28:51 +08:00
    谢谢各位
    OK 了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   802 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 22:20 · PVG 06:20 · LAX 15:20 · JFK 18:20
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.