指定的值不符合要求的格式
The specified value does not conform to the required format
我在 django
模板中有这个代码片段
<td><input type="datetime-local" id="tdId_{{i.0}}5" value="{{i.4|date:'Y-m-d H:i'}}"/></td>
控制台写
The specified value ... does not conform to the required format. ...
我应该使用哪个掩码来匹配datetime-local
的要求格式?
datetime-local
接受 ISO 8601
日期格式。根据 documentation,您可以使用格式字符 c
将日期时间对象转换为 ISO 8601 format
<input type="datetime-local" id="tdId_{{i.0}}5" value="{{i.4|date:'c'}}"/>
此解决方案也有效:
{{ i.4|date:'Y-m-d'}}T{{ i.4|time:'H:i:s' }}
所以,整个代码是:
<input type="datetime-local" id="tdId_{{i.0}}5" value="{{ i.4|date:'Y-m-d'}}T{{ i.4|time:'H:i:s' }}"/>
我在 django
模板中有这个代码片段
<td><input type="datetime-local" id="tdId_{{i.0}}5" value="{{i.4|date:'Y-m-d H:i'}}"/></td>
控制台写
The specified value ... does not conform to the required format. ...
我应该使用哪个掩码来匹配datetime-local
的要求格式?
datetime-local
接受 ISO 8601
日期格式。根据 documentation,您可以使用格式字符 c
将日期时间对象转换为 ISO 8601 format
<input type="datetime-local" id="tdId_{{i.0}}5" value="{{i.4|date:'c'}}"/>
此解决方案也有效:
{{ i.4|date:'Y-m-d'}}T{{ i.4|time:'H:i:s' }}
所以,整个代码是:
<input type="datetime-local" id="tdId_{{i.0}}5" value="{{ i.4|date:'Y-m-d'}}T{{ i.4|time:'H:i:s' }}"/>