微信小程序計時


var intt;
Page({
  data: {
    hour: 0,
    minute:0,
    second:0,
    millisecond:0,
    int: '00:00:00',
    cost: 0,
    flag:1,
    endtime:"",
  },
  onLoad: function () {
    
  },
  //開始
  start:function(){
    var that = this;
    //停止(暫停)
    clearInterval(intt);
    //時間重置
    that.setData({
      hour: 0,
      minute: 0,
      second: 0,
      millisecond: 0,
      int: '00:00:00',
    })
    intt = setInterval(function () { that.timer() }, 50);
  },
  //暫停
  stop:function(){
    clearInterval(intt);
  },
  //停止
  Reset:function(){
    var that = this
    clearInterval(intt);
    that.setData({
      hour: 0,
      minute: 0,
      second: 0,
      millisecond: 0,
      int: '00:00:00',
    })
  },
  timer:function(){
    var that = this;
    console.log(that.data.millisecond)
    that.setData({
      millisecond:that.data.millisecond + 5
    })
    if (that.data.millisecond >= 100) {
      that.setData({
        millisecond:0,
        second:that.data.second+1
      })
    }
    if (that.data.second >= 60) {
      that.setData({
        second:0,
        minute:that.data.minute + 1
      })
    }

    if (that.data.minute >= 60) {
      that.setData({
        minute:0,
        hour:that.data.hour + 1
      })
    }
    that.setData({
      int:that.data.hour + ":" + that.data.minute + ":" + that.data.second + ":" + that.data.millisecond
    })
  },
});


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM