Javascript Reference - HTML DOM Input Time value Property








The value property sets or gets the value attribute of a time field.

The value attribute specifies a time for the time field.

Browser Support

value Yes No No Yes Yes

Syntax

Return the value property.

var v = timeObject.value 

Set the value property.

timeObject.value=hh:mm:ss.ms




Property Values

Value Description
hh:mm:ss.ms Specifies a time for the time field.
  • hh - hour (e.g. 22 for 10.00pm)
  • mm - minutes (e.g. 31)
  • ss - seconds (e.g. 01)
  • ms - milliseconds (e.g 21)

Return Value

A String type value representing the time of the time field.

Example

The following code shows how to get the time of a time field.


<!DOCTYPE html>
<html>
<body>
<!--from  w w w  . j a  v a 2s .c  om-->
Time: <input type="time" id="myTime" value="21:32:55">
<button onclick="myFunction()">test</button>
<p id="demo"></p>

<script>
function myFunction() {
    var x = document.getElementById("myTime").value;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows:





Example 2

The following code shows how to set a time for a time field.


<!DOCTYPE html>
<html>
<body>
Time: <input type="time" id="myTime">
<button onclick="myFunction()">test</button>
<!--  w w  w .  j  a  va  2 s .c  om-->
<p id="demo"></p>

<script>
function myFunction() {
    document.getElementById("myTime").value = "22:53:05";
}
</script>

</body>
</html>

The code above is rendered as follows: