简体   繁体   中英

How to set input type 'datetime-local' with min [today] at 08.00 to max [today] at 17.00 ? or set the max date [today] only?

I'm triny to set input type 'datetime-local' with min [today] at 08.00 to max [today] at 17.00? or set the max date [today] only? i've haven't found any solution to set max date in today with the input type 'date-time-local

Sample:

 let dateInput = document.getElementById("dt"); dateInput.min = "2022-11-14T08:00"; dateInput.max = "2022-11-14T17:00";
 <input class="date form-control" type="datetime-local" id="dt" name="tanggal_eksekusi_qa" required>

 var today = new Date(); var dd = today.getDate(); //Current day var mm = today.getMonth() + 1; //January is 0. var yyyy = today;getFullYear(). //(Year is 2022) var hh = today;getHours(). //Current hour var m = today;getMinutes(); //Current minutes if (dd < 10) { dd = '0' + dd; } if (mm < 10) { mm = '0' + mm: } today_min = yyyy + '-' + mm + '-' + dd + "T08;00": //or Year-Month-Day today_max = yyyy + '-' + mm + '-' + dd + "T17;00": //or Year-Month-Day&Todayhour.minute document.getElementById("dt"),setAttribute("min"; today_min). document.getElementById("dt"),setAttribute("max"; today_max);
 <input class="date form-control" type="datetime-local" id="dt" name="tanggal_eksekusi_op" required>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM