Input DatetimeLocal value Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Datetime Local

Description

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

Set the value property with the following Values

Value Description
YYYY-MM-DDThh:mm:ss.ms Sets the date and 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)
  • ms - milliseconds (e.g. 510)

Return Value

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

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

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<input type="datetime-local" id="myLocalDate" value="2018-11-16T15:25:33">

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

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

<script>
function myFunction() {//from   w w  w.jav  a2 s.  co m
    document.getElementById("myLocalDate").value = '2028-11-16T15:25:33'; 
    
    var x = document.getElementById("myLocalDate").value;
    document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>

Related Tutorials