简体   繁体   中英

How to restrict the current date based on the hours and minutes in javascript

Disable the current date if the hour exceeds the current date hours using javascript.

I tried like this :

var d = new Date();
var restricttime = '<?php echo $restrictTime->time_restriction ?>';
var restrictmin = '<?php echo $restrictTime->restrict_min ?>';

var hour = d.getHours();
var minutes_hr = d.getMinutes();

if (restricttime >= hour) {
    if (minutes_hr > restrictmin && restricttime >= hour) {
        min_Date = 0;
    } else {
        min_Date = 1;
    }
} else {
    min_Date = 0;
}

$("#datepicker-13").datepicker({
    minDate: min_Date
});

I think the logic is not correct in this. Please help me out.

You can use the relative date properties. Check if this works.

    if(minutes_hr > restrictmin && restricttime >= hour){
          min_Date= "-1d";
    }else{ 
          min_Date= new Date();
    }

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