js倒计时60s





    
    
    
    
    
    
    
    
    
    手机注册
    




    
          




//时分秒倒计时
//不足两位补0
        function timeS(num) {
            return ('0' + num).slice(-2);
        }
        function moveTime() {

            var starttime = $(".w_sp2").attr("starttime").replace(/-/g, '/');
            var endtime = $(".w_sp2").attr("endtime").replace(/-/g, '/'); //苹果浏览器不识别new Date('2013-10-21'),只识别new Date('2013/10/21');
            var startTime = new Date(starttime).getTime();
            var endTime = new Date(endtime).getTime();
            var differTime = endTime - startTime; //两时间差
            
            function FreshTime() {

                var d = parseInt(differTime / (24 * 60 * 60 * 1000));
                var h = parseInt(differTime / (60 * 60 * 1000) % 24);
                var m = parseInt(differTime / (60 * 1000) % 60);
                var s = parseInt(differTime / 1000 % 60);
                var t_html = d + "天" + timeS(h) + "时" + timeS(m) + "分" + timeS(s) + "秒";
                $(".w_sp2").html(t_html);
                if (differTime <= 0) {
                    $(".w_sp2").html('当前价格已失效');
                    $(".i_contThr").hide()
                    clearInterval(timer);
                }
                differTime = differTime - 1000;
            }
            FreshTime();
            var timer = setInterval(FreshTime, 1000);
        }

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