Get the maximum date and time allowed for a datetime field:
var x = document.getElementById("myDatetime").max;
Click the button to display the value of the max attribute of the datetime field.
<!DOCTYPE html> <html> <body> Enter a date and time between 2000-01-01 10:57 PM and 2014-02-06 10:57 PM: <input type="datetime" id="myDatetime" min="2000-01-01T22:57Z" max="2014-02-06T22:57Z"> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {//from w w w . ja va2s . c o m var x = document.getElementById("myDatetime").max; document.getElementById("demo").innerHTML = x; } </script> </body> </html>
The max
property sets or gets the value of the max attribute of a datetime field.
The max
attribute specifies the maximum value of date and time for a datetime field.
The max
property accepts and returns a String type value.
Property Values
Value | Description |
---|---|
YYYY-MM-DDThh:mm:ssTZD Specifies the maximum date and/or time allowed for the datetime field. 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) |
The max
property returns String representing the maximum date and time allowed.