Javascript DOM HTML Input Datetime value Property set

Introduction

Set a date and time for a datetime field:

document.getElementById("myDatetime").value = "2014-01-02T11:42Z";

Click the button to set a date and time for the datetime field.

View in separate window

<!DOCTYPE html>
<html>
<body>

Date: <input type="datetime" id="myDatetime">
<button onclick="myFunction()">Test</button>
<p id="demo"></p>

<script>
function myFunction() {/*from   ww  w . j  a  va  2 s . co m*/
  document.getElementById("myDatetime").value = "2014-01-02T11:42Z";
}
</script>

</body>
</html>

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

The value attribute sets a date and time for the datetime field.

The value property accepts and returns a String value.

Property Values

Value
Description
YYYY-MM-DDThh:mm:ssTZD Specifies the date and/or time.
YYYY - year (e.g. 2020)
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 denotes Zulu, which is Greenwich Mean Time)



PreviousNext

Related