js计算剩余分钟

// 剩余时间提醒
    function checkTime() {
        if (timeCompare()) {
            document.getElementById('distanceDeadline').innerHTML = "距离截止时间:已超时";
        } else {
            var now = new Date();
            var nowTime = now.getTime();
            var year = now.getFullYear();
            var month = now.getMonth() + 1;//js从0开始取
            var date = now.getDate();
            var deadlineStr = year + "/" + month + "/" + date + " " + "16:30:00";
            var deadline = Date.parse(deadlineStr);
            var timeDisparity = (deadline - nowTime)/60000;
            document.getElementById('distanceDeadline').innerHTML = "距离截止时间:" + (Math.ceil(timeDisparity)) + "分钟";
        }
    }

 

posted @ 2018-12-05 09:43  anderson_1996  阅读(1413)  评论(0编辑  收藏  举报