Input Datetime value Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Datetime

Description

The value property sets or gets the value attribute of a datetime field, which controls date and time for the datetime field.

Set the value property with the following Values

Value Description
YYYY-MM-DDThh:mm:ssTZD Sets the date and/or time.
  • YYYY - year (e.g. 2011)
  • MM - month (e.g. 01 for January)
  • DD - day of the month (e.g. 08)
  • T - a required separator if time is also specified
  • hh - hour (e.g. 22 for 10.00pm)
  • mm - minutes (e.g. 55)
  • ss - seconds (e.g. 03)
  • TZD - Time Zone Designator (Z as Greenwich Mean Time)

Return Value

A String, representing the date and time of the datetime field

The following code shows how to Set a date and time for a datetime field:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>
Date: <input type="datetime" id="myDatetime" value="2018-02-06T10:57Z">

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {/*from ww  w . j a va2s  . c o  m*/
    document.getElementById("myDatetime").value = '2018-03-06T10:57Z';
    var x = document.getElementById("myDatetime").value;
    document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>

Related Tutorials