【问题标题】:Django template convert datetime-local formatDjango 模板转换 datetime-local 格式
【发布时间】:2020-11-15 21:04:35
【问题描述】:

我在如何将datetime 格式从db 转换为html datetime-local 时遇到问题。这是我数据库中的数据格式:

2020-07-18T17:25:00Z

当我尝试将此数据传递给具有 datetime-local 类型的 html 输入时,它会给我这样的警告:

这是我的带有格式化值的 html 代码:

<input type="datetime-local" required="" value="{{order.pick_up_datetime|date:'Y-m-dTh:i a'}}">

【问题讨论】:

    标签: html datetime django-templates datetime-format django-3.0


    【解决方案1】:

    经过一天的调试,我在这里得到了问题的答案。我只是做了这样的事情:

    <input type="datetime-local" required="" value="{{order.pick_up_datetime|date:'Y-m-d'}}T{{order.pick_up_datetime|time:'H:i:s'}}">
    

    只需将值中datetime的值分开并添加TT只是standard (ISO 8601)分隔时间的方式)。

    这里的答案帮助我意识到并解决了我的问题:Why does DateTime add a T separator to the timestamp?

    【讨论】:

      猜你喜欢
      • 2016-12-23
      • 2010-11-13
      • 2014-07-27
      • 2020-10-27
      • 2021-06-02
      • 1970-01-01
      • 2018-08-25
      • 2015-04-29
      • 2023-03-21
      相关资源
      最近更新 更多