倒计时

function good(n){
  var toDate = new Date(n*1000);
  var toTime = Math.floor(toDate.getTime()/1000);
  toTimer();
  setInterval(toTimer,1000);
  function toTimer()
  {
  var nowDate = new Date();
  var nowTime = Math.floor(nowDate.getTime()/1000);
  var day = Math.floor((toTime-nowTime)/86400);
  var hour = Math.floor((toTime-nowTime)%86400/3600);
  var minute = Math.floor((toTime-nowTime)%86400%3600/60);
  var second = Math.floor((toTime-nowTime)%86400%3600%60);
  console.log(day+'天'+p(hour)+':'+p(minute)+':'+p(second)+'后开始');
  }
  function p(s) {
    return s < 10 ? '0' + s: s;
  }
}

 

good(结束时间戳)

posted @ 2018-04-13 17:58  我以为你不在乎  阅读(82)  评论(0编辑  收藏  举报