美文网首页
倒计时功能

倒计时功能

作者: zZ_d205 | 来源:发表于2022-06-20 15:25 被阅读0次
  //  是否过期
    compareTime() {
      const nowTime = new Date().getTime()
      if (this.endTime < nowTime) {
        this.endTimeHtml = '00: 00 :00'
        window.clearInterval(this.timer)
        this.$confirm('订单已超时', '提示', {
          showConfirmButton: false,
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {

        }).catch(() => {
          this.$router.push({ name: 'LatestActivities' })
        });
      } else {
        const lefttime = Math.floor((this.endTime - nowTime) / 1000) // 距离结束时间的毫秒数
        var day = this.totwo(Math.floor(lefttime / 86400));// 差值/60/60/24获取天数
        var hour = this.totwo(Math.floor(lefttime % 86400 / 3600)); //  取余/60/60获取时(取余是获取conS对应位置的小数位)
        var min = this.totwo(Math.floor(lefttime % 86400 % 3600 / 60));// 取余/60获取分
        var s = this.totwo(Math.floor(lefttime % 60)); // 取总秒数的余数
        this.endTimeHtml = hour + ':' + min + ':' + s
      }
    },
    totwo(e) {
      return e < 10 ? '0' + e : '' + e;// 如果取得的数字为个数则在其前面增添一个0
    },

相关文章

网友评论

      本文标题:倒计时功能

      本文链接:https://www.haomeiwen.com/subject/acjysrtx.html