时间差倒计时

223 阅读1分钟

时间差倒计时 距离2022年11月20日0点

        //获取当前时间
        var nowTime = new Date();
        //定义倒计时时间
        var birthTime = new Date(2022, 10, 20, 00, 00, 00);
        console.log(birthTime);
        //获取当前时间的秒数
        var nowTimeSec = nowTime.getTime();
        //获取总秒数差(定点时间-当前时间)
        var birthTimeSec = birthTime.getTime();
        var timeCount = (birthTimeSec - nowTimeSec) / 1000;

        //体现天数
        var day = parseInt(timeCount / (60 * 60 * 24));
        console.log(day);

        //体现小时数
        var hours = parseInt((timeCount / (60 * 60)) - 24 * day);
        console.log(hours);

        //体现分钟数;
        var minutes = parseInt((timeCount / 60) - (hours * 60) - day * 24 * 60);

        //体现秒数;
        var seconds = parseInt(timeCount % 60);
        console.log(seconds);

        console.log(`距离28岁还有${day}天,${hours}小时,${minutes}分钟,${seconds}秒`);