Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Input time [type= time] setting value

Hoe to set up a value, to input type = time , set in html using value attribute value.

I have tried:

var tm =  new Date();

var in= "<input type='time' name='time' id='tm' value='" + tm + "'/>";

it does not work

like image 601
Emmanuel N Avatar asked May 23 '13 16:05

Emmanuel N


People also ask

How do I add AM PM to input type time?

If you want the time with AM & PM, check the first two values, and utilize something like the following: if(FirstTwoNums > 12){ FirstTwoNums -= 12; PM = true;}/*else, PM is false */ .

How do you select time in HTML?

The <input type="time"> defines a control for entering a time (no time zone).


1 Answers

Use the valueAsDate attribute to convert between a Date object and an input element’s value.

> var elem = document.createElement('input');
> elem.type = 'time';
> elem.valueAsDate = new Date(1970, 1, 1, 7, 34);
> elem.value
"12:34"
like image 91
Josh Lee Avatar answered Sep 20 '22 12:09

Josh Lee