ionic3+angular 倒计时效果

// 声明变量
  applicationInterval: any; // 定时器
  nextBtnText: String;
  nextBtnBool: Boolean;
  // 使用定时器,每秒执行一次
  ionViewDidEnter() {
    let that = this;
    let applicationPageOpenData: number = parseInt(((new Date().getTime() / 1000) + 120).toString()); //120是设置的秒数
    let nowDte: number;
    this.nextBtnText = "30秒后方可点击"; // 按钮文本
    this.nextBtnBool = false; // 按钮是否可点击标识
    this.applicationInterval = setInterval(() => {
      nowDte = parseInt((new Date().getTime() / 1000).toString());
      console.log(nowDte);
      let receiveDate = applicationPageOpenData - nowDte;
      if (receiveDate > 0) {
        let tss = this.s_to_hs(receiveDate);
        that.nextBtnText = tss + "秒后方可点击";
        
        console.log(this.s_to_hs(receiveDate));
      } else {
        that.nextBtnText = "下一步";
        that.nextBtnBool = true;
        // 停止定时器
        clearInterval(that.applicationInterval);
      }
    }, 1000);
  }
  s_to_hs(s){
    //计算分钟
    //算法:将秒数除以60,然后下舍入,既得到分钟数
    var h;
    h  =   Math.floor(s/60);
    //计算秒
    //算法:取得秒%60的余数,既得到秒数
    s  =   s%60;
    //将变量转换为字符串
    h    +=    '';
    s    +=    '';
    //如果只有一位数,前面增加一个0
    h  =   (h.length==1)?'0'+h:h;
    s  =   (s.length==1)?'0'+s:s;
    console.log(h+':'+s);
    return h+':'+s;
  }

 

转载于:https://www.cnblogs.com/opcec/p/9876937.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值