Javascript Reference - HTML DOM Input DatetimeLocal value Property








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

Browser Support

value Yes No No Yes Yes

Syntax

Return the value property.

var v = datetimelocalObject.value

Set the value property.

datetimelocalObject.value=YYYY-MM-DDThh:mm:ss.ms

Property Values

Value Description
YYYY-MM-DDThh:mm:ss.ms Specifies the date and time.
  • YYYY - year (e.g. 2014)
  • MM - month (e.g. 01 for January)
  • DD - day of the month (e.g. 09)
  • T - a required separator for time
  • hh - hour (e.g. 22 for 10.00pm)
  • mm - minutes (e.g. 51)
  • ss - seconds (e.g. 01)
  • ms - milliseconds (e.g. 511)




Return Value

A String type value representing the date and time of the local datetime field.

Example

The following code shows how to get the local date and time of a datetime field.


<!DOCTYPE html>
<html>
<body>
<input type="datetime-local" id="myLocalDate" value="2014-11-16T15:25:33">
<button onclick="myFunction()">test</button>
<!--from w  w  w .j  av  a2 s . c om-->
<p id="demo"></p>

<script>
function myFunction() {
    var x = document.getElementById("myLocalDate").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 local date and time for a datetime field.


<!DOCTYPE html>
<html>
<body>
<!--from   ww w. ja  v a 2  s .co  m-->
Date: <input type="datetime-local" id="myLocalDate">
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
    document.getElementById("myLocalDate").value = "2014-01-02T11:22:13.511";
}
</script>

</body>
</html>

The code above is rendered as follows: