微信小程序倒计时

 //倒计时
  leftTimer: function (time) {
    var that = this;
    var leftTime = new Date(time) - (new Date()); //计算剩余的毫秒数 
    var hours = that.data.hours;
    var minutes = that.data.minutes;
    hours = parseInt(leftTime / 1000 / 60 / 60 % 24, 10); //计算剩余的小时 
    minutes = parseInt(leftTime / 1000 / 60 % 60, 10);//计算剩余的分钟 
    hours = that.checkTime(hours);
    minutes = that.checkTime(minutes);
    that.setData({
      hours: hours,
      minutes:minutes
    })
  },
  //将0-9的数字前面加上0,例1变为01
  checkTime: function (i) {
    if (i < 10) {
      i = "0" + i;
    }
    return i;
  },

 

posted @ 2018-07-09 17:13  刘倩蓉  阅读(343)  评论(0编辑  收藏  举报