js 比较日期

        // 获取当前日期
        let currentDate = new Date();
        let str = "" + currentDate.getFullYear() + "-";
        str += (currentDate.getMonth() + 1) + "-";
        str += currentDate.getDate();
        let today = new Date(str.replace("-", "/").replace("-", "/"));
        
        //获取输入的日期
        var date = $("#date").val();
        
        let fulfill_appointment_time = new Date(date.replace("-", "/").replace("-", "/"));
        if (fulfill_appointment_time < today) {
            alert('预约时间不能晚于今天');
        }

 

你可能感兴趣的:(js 比较日期)