时间计时

2018-12-04  本文已影响0人  Forever_f59e
    window.onload = function(){
                 var odiv = document.getElementById('div1')
                function timeLeft(){
                            var now = new Date();
                            var future = new Date(2018,11,13,0,0,0); 
                            var mill = parseInt((future - now) / 1000);
                            var day = parseInt(mill/86400);
                            var hour = parseInt((mill%86400) / 3600);
                            var minute = parseInt(((mill%86400)%3600)/60);
                            var sencond = mill %60;
                            odiv.innerHTML = '距离2018年12月13日00时00分00秒还有' + day + '天'
        + toDouble(hour) + '时' + toDouble(minute) + '分' + toDouble(sencond) + '秒'
            }
            timeLeft();
            setInterval(timeLeft,1000);
              };
      function toDouble(num){
            if(num<10){
                      return '0' + num;
                        }else{
                                    return num;
                    }
              }
    }
上一篇 下一篇

猜你喜欢

热点阅读