Reputation: 15349
Can someone explain why when I set the default value of a datetime-local input with seconds other than :00, the browser gives me an error of "Invalid value."?
This may be a bug in Chrome's implementation of datetime-local since this bug does not appear in the latest Firefox and Safari.
Error in Chrome: 30.0.1599.69
Chrome Canary: 32.0.1665.2 canary
This works:
<input type="datetime-local" name="pub_date" value="2013-10-09T15:38:00">
But this does not:
<input type="datetime-local" name="pub_date" value="2013-10-09T15:38:15">
Per the W3 Spec for the datetime-local input element, the value attribute should contain "A string representing a local date and time."
Example:
1985-04-12T23:20:50.52
1996-12-19T16:39:57
I tried both of the above examples and they don't work either.
Update: Confirmed Bug & Solution
This behavior is a known bug.
As of today, the quick fix is to add the step attribute like so for non-zero seconds:
<input type="datetime-local"
name="pub_date"
value="2013-10-09T15:38:15"
step="1">
Upvotes: 31
Views: 17679
Reputation: 112
This works in Chrome Version 52.0.2743.116 m
<input type="datetime-local" name="pub_date" value="2013-10-09T15:38:15" />
Upvotes: 3
Reputation: 593
Chrome browser require date in "yyyy-MM-ddThh:mm" followed by optional ":ss" or ":ss.SSS" format. So when we assign Date and Time, we need to assign it in required format otherwise it won't show the Date Time. Even we can confirm from browser inspector tool [Ctrl+I] in console tab.
Upvotes: 1
Reputation: 1
Chrome is looking for a complete Time Stamp there is really no way around putting one. Just zero out your milliseconds and you should be good.
Upvotes: 0