倒计时

        
       var activity_endts = 1537999200 * 1000;//活动结束时间戳 (毫秒级)
       
            
       run(activity_endts);
                    
        

        //定时器
        function run(enddate){
            var time = 1000; 
            var interval = setInterval(function(){
                //计算时间相差
                var date = enddate - new Date().getTime(); 
                if(date <= 0){
                    $('.day').html(0);
                    $('.hour').html(0);
                    $('.minutes').html(0);
                    $('.seconds').html(0);
                    clearInterval(interval);
                    return;
                }
                var days    = date / 1000 / 60 / 60 / 24;
                var daysRound   = Math.floor(days);
                var hours    = date/ 1000 / 60 / 60 - (24 * daysRound);
                var hoursRound   = Math.floor(hours);
                var minutes   = date / 1000 /60 - (24 * 60 * daysRound) - (60 * hoursRound);
                var minutesRound  = Math.floor(minutes);
                var seconds   = date/ 1000 - (24 * 60 * 60 * daysRound) - (60 * 60 * hoursRound) - (60 * minutesRound);
                var secondsRound  = Math.floor(seconds);
                $('.day').html(daysRound);
                $('.hour').html(hoursRound);
                $('.minutes').html(minutesRound);
                $('.seconds').html(secondsRound);
            },time);
        }
            
5 20 小时 9 57

 

你可能感兴趣的:(js,js,倒计时)