呈现倒计时时间(剩余时间:09天01时10分12秒)

var date1 = new Date(); //实例化现在的时间
        var date2 = new Date('2020-12-30 20:36-58');
        var dateDis = (date2 - date1) / 1000; //相差的总秒数
        var days = parseInt(dateDis / 60 / 60 / 24); //相差总天数
        days = days > 10 ? days : "0" + days;
        var hours = parseInt(dateDis / 60 / 60 % 24); //相差总小时数
        hours = hours > 10 ? hours : "0" + hours;
        var minutes = parseInt(dateDis / 60 % 60); //相差总分钟数
        minutes = minutes > 10 ? minutes : "0" + minutes;
        var seconds = parseInt(dateDis % 60); //相差的总秒数
        seconds = seconds > 10 ? seconds : "0" + seconds;
        console.log("剩余时间为:" + days + "天" + hours + "时" + minutes + "分钟" + seconds + "秒");

 

posted @ 2023-02-13 11:32  芬-mi  阅读(112)  评论(0编辑  收藏  举报