微信小程序js倒计时功能

时间:2024-03-10 09:59:46

//倒计时方法

var that=this;
    this.data.intervarID= setInterval(function () {
      var leftTime = (new Date(2017, 6-1, 28, 17, 40, 0)) - (new Date()); //计算剩余的毫秒数 
      var days = parseInt(leftTime / 1000 / 60 / 60 / 24, 10); //计算剩余的天数 
      var hours = parseInt(leftTime / 1000 / 60 / 60 % 24, 10); //计算剩余的小时 
      var minutes = parseInt(leftTime / 1000 / 60 % 60, 10);//计算剩余的分钟 
      var seconds = parseInt(leftTime / 1000 % 60, 10);//计算剩余的秒数 
      days = checkTime(days);
      hours = checkTime(hours);
      minutes = checkTime(minutes);
      seconds = checkTime(seconds);
      that.setData({
        clock: days + "" + hours + "小时" + minutes + "" + seconds + ""
      })
      if (days == \'00\' && hours == \'00\' && minutes == \'00\' && seconds==\'00\')
      {
        clearInterval(that.data.intervarID);

        that.setData({
          btnname: \'立即抢购\'
        })
      }
    }, 1000
    )