Input DatetimeLocal value Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Datetime Local


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 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>

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

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

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

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;

Related Tutorials