Can't set initial value of input element with type = "time" in Chrome

I love that Chrome gives you masking / formatting automatically when you use the type = "time" attribute / value. But I am unable to set an initial value for the control.

It:

<input type="time" value="05:00 PM" />

      

Just shows up as blank (masked) in Chrome. And when my form is submitted, it submits it as empty.

I guess it has to do with the format of the string I am setting in the value. But I don't know what the correct format is (and why the format I was using didn't work) seems like a reasonable time format to me).

Here's a jsfiddle to play with just in case you want it.

Any suggestions?

+3


source to share


2 answers


Try something like:

<input type="time" value="17:00:00" />

      



Read this .

+2


source


So, for the specification :

Value: A valid partial time as defined in [RFC 3339].

Referring to RFC 3339 , specifically section 5.6 in the footnote. Here you will find that it is defined as



partial-time    = time-hour ":" time-minute ":" time-second
                  [time-secfrac]

      

So in practice this means that you cannot use anything like PM or AM in the meaning, although the browser may decide to represent the time in any way it wishes (depending on how the user chooses sometimes even). The value you get when you submit the form will always be in the above format.

+1


source







All Articles