0

我使用此代码禁用过去的时间(https://thecodedeveloper.com/disable-past-date-time/),但我得到了接送日期和时间(.datetimepickerp)和下车日期和时间(.datetimepickerd ),我想设置下车日期和时间必须大于取车日期和时间。任何人都可以帮忙吗?

var checkPastTime = function(inputDateTime) {
    if(typeof(inputDateTime) != "undefined" && inputDateTime !== null) {
        var current = new Date();
        
        //check past year and month
        if(inputDateTime.getFullYear() < current.getFullYear()) {
            $('.datetimepickerp').datetimepicker('reset');
            alert("Sorry! Past date time not allow.");
        } 
        else if((inputDateTime.getFullYear() == current.getFullYear()) && (inputDateTime.getMonth() < current.getMonth())) {
            $('.datetimepickerp').datetimepicker('reset');
            alert("Sorry! Past date time not allow.");
        }
       
        // 'this' is jquery object datetimepicker
        // check input date equal to todate date
        if (inputDateTime.getDate() == current.getDate()) {
            if(inputDateTime.getHours() < current.getHours()){
              $('.datetimepickerp').datetimepicker('reset');
            }
            this.setOptions({
                minTime: current.getHours() + ':00' //here pass current time hour
            });
        }
        else {
            this.setOptions({
                minTime: false
            });
        }
    }
};

var currentYear = new Date();
$('.datetimepickerp').datetimepicker({
    format:'Y-m-d H:i',
    minDate : 0,
    dayOfWeekStart: 0,
    yearStart : currentYear.getFullYear(), // Start value for current Year selector
    onChangeDateTime:checkPastTime,
    onShow:checkPastTime
});

而ex现在是下午4:22,如何设置禁用下午4点和通过时间,只能选择下午5点和下午5点之后的时间?

4

0 回答 0