Reputation: 2197
I have one get and post APIs which involve date-time-local input. First I sent the date-time values to the server via post API and then get the same values from the get method.
the same date-time value with the same format I received from the server but when I set it as the input date-time-local value, it was not visible.
My input type
<input type="datetime-local" name="year" class="form-control" value={this.state.dateTime} />
//value coming from the server is in the format of 2021-11-11T16:27:00Z
I faced this error in the console
The specified value "2021-11-11T16:27:00Z" does not conform to the required format. The format is "yyyy-MM-ddThh:mm" followed by optional ":ss" or ":ss.SSS".
I also tried to convert server string values to the date object but it did not work.
Upvotes: 0
Views: 1235
Reputation: 381
Try passing this.state.dateTime.toLocalString()
into your input. This looks like it would generate the format it needs.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString
Upvotes: 1