Javascript DOM HTML Input DatetimeLocal value Property set

Introduction

Set a local date and time for a datetime field:

document.getElementById("myLocalDate").value = "2020-01-02T11:42:42.510";

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

View in separate window

<!DOCTYPE html>
<html>
<body>

Date: <input type="datetime-local" id="myLocalDate">
<button onclick="myFunction()">Test</button>
<script>
function myFunction() {//  w  w  w  .  j  a v a 2s.co m
  document.getElementById("myLocalDate").value = "2020-01-02T11:42:42.510";
}
</script>

</body>
</html>

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

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

Property Values

Value
Description
YYYY-MM-DDThh:mm:ss.ms Specifies the date and 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)
ms - milliseconds (e.g. 510)
Return Value: A String, representing the date and time of the local datetime field



PreviousNext

Related