Javascript Reference - HTML DOM Input Datetime value Property








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

Browser Support

value No No No No No

Syntax

Return the value property.

var v = datetimeObject.value

Set the value property.

datetimeObject.value=YYYY-MM-DDThh:mm:ssTZD

Property Values

Value Description
YYYY-MM-DDThh:mm:ssTZD Set the date and/or time.
  • YYYY - year (e.g. 2014)
  • MM - month (e.g. 01 for January)
  • DD - day of the month (e.g. 01)
  • T - a required separator for time field
  • hh - hour (e.g. 22 for 10.00pm)
  • mm - minutes (e.g. 51)
  • ss - seconds (e.g. 01)
  • TZD - Time Zone Designator




Return Value

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

Example

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


<!DOCTYPE html>
<html>
<body>
<!--  w w w.  j  av  a 2s . c o  m-->
Date: <input type="datetime" id="myDatetime" value="2014-02-06T10:27Z">
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
    var x = document.getElementById("myDatetime").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 date and time for a datetime field.


<!DOCTYPE html>
<html>
<body>
Date: <input type="datetime" id="myDatetime">
<button onclick="myFunction()">test</button>
<!--from   ww w.j  a  v  a2  s  . c  o  m-->
<p id="demo"></p>

<script>
function myFunction() {
    document.getElementById("myDatetime").value = "2014-01-12T11:12Z";
}
</script>

</body>
</html>

The code above is rendered as follows: