Home > OS >  The specified value does not conform to the required format
The specified value does not conform to the required format

Time:12-28

I have this code snippet in django template

<td><input type="datetime-local" id="tdId_{{i.0}}5" value="{{i.4|date:'Y-m-d H:i'}}"/></td>

The console writes The specified value ... does not conform to the required format. ...

Which mask should I use to match the required format of datetime-local?

CodePudding user response:

datetime-local accepte ISO 8601 date format. accoring to the documentation you can use the Format character c to convert a datetime object to an ISO 8601 format

<input type="datetime-local" id="tdId_{{i.0}}5" value="{{i.4|date:'c'}}"/>

CodePudding user response:

this solution is also working:

{{ i.4|date:'Y-m-d'}}T{{ i.4|time:'H:i:s' }}

So, the whole code be:

<input type="datetime-local" id="tdId_{{i.0}}5" value="{{ i.4|date:'Y-m-d'}}T{{ i.4|time:'H:i:s' }}"/>
  • Related