小程序倒计时功能

  //倒计时
  countDown: function () {
    var that = this;
    var nowTime = new Date().getTime() / 1000; //现在时间(时间戳)
    var endTime = that.data.orderData.send_expired; //结束时间(时间戳)
    var time = endTime - nowTime; //距离结束的毫秒数
    // 获取时、分、秒
    that.data.timer = setInterval(function () {
      if (time <= 0) {
        clearInterval(that.data.timer);
        that.loadData();
      } else {
        time--;
        let hou = parseInt(time / 3600);
        let min = parseInt((time % 3600) / 60);
        let sec = parseInt(((time % (60 * 60 * 24)) % 3600) % 60);
        that.setData({
          hou: that.timeFormat(hou),
          min: that.timeFormat(min),
          sec: that.timeFormat(sec), //对接完,看看就删除
        });
      }
    }, 1000);
  },
  //小于10的格式化函数(2变成02)
  timeFormat(param) {
    return param < 10 ? '0' + param : param;
  },
posted @ 2020-11-16 10:27  吸取天地精华  阅读(308)  评论(0)    收藏  举报