Javascript DOM HTML Input DatetimeLocal max Property

Introduction

Get the maximum date and time allowed for a local datetime field:

var x = document.getElementById("myLocalDate").max;

Click the button to display the value of the max attribute of the local datetime field.

View in separate window

<!DOCTYPE html>
<html>
<body>

Enter a date and time between 2000-10-06 22:22:55 and 2014-11-16 21:25:33:
<input type="datetime-local" id="myLocalDate" min="2000-10-06T22:22:55" max="2014-11-16T21:25:33">
<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {/*  w w  w  . ja  v  a2  s .  com*/
  var x = document.getElementById("myLocalDate").max;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

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

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

Data format:

Value Description
YYYY-MM-DDThh:mm:ss.ms Specifies the maximum date and time allowed for the local datetime field.

Components of the value:

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

The max property returns a string representing the maximum date and time allowed.




PreviousNext

Related