js毫秒转换天时分秒/动态倒计时

<script language="JavaScript">
  
  function getQueryString(name) {
    var reg =new RegExp("(^|&)"+ name +"=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r !=null) return unescape(r[2]); returnnull;
  }

  var currentDate = new Date();
  var strEndTime = getQueryString("EndTime");
  var EndTime=new Date(strEndTime);
  
  var days= EndTime - currentDate; 
  EndTimeMsg = parseInt(days / 1000);//精确到秒

  function show() {
    h = Math.floor(EndTimeMsg / 60 / 60);
    m = Math.floor((EndTimeMsg - h * 60 * 60) / 60);
    s = Math.floor((EndTimeMsg - h * 60 * 60 - m * 60));
    document.getElementById("DD").innerHTML = parseInt(h/24);
    document.getElementById("HH").innerHTML = h;
    document.getElementById("MM").innerHTML = m;
    document.getElementById("SS").innerHTML = s;
    EndTimeMsg--;
    if (EndTimeMsg < 0)
    {
        document.getElementById("DD").innerHTML = "0";
        document.getElementById("HH").innerHTML = "00";
        document.getElementById("MM").innerHTML = "00";
        document.getElementById("SS").innerHTML = "00";;
    }
  }
  setInterval("show()", 1000)
  
</script>
<div>
  <strong id="DD"></strong>天 <strong id="HH"></strong>时 <strong id="MM"></strong>分 <strong id="SS"></strong></div>

 

posted @ 2016-12-05 13:58  weixin186  阅读(4645)  评论(0编辑  收藏  举报