js-秒数转为XX时XX分XX秒(用于计算剩余时间或倒计时)


export default {
  data() {
    return {
      hours: null,
      minute: null,
      second: null
    }
  },
  methods: {
    // 秒数 转为 XX时XX分XX秒   time = 传入的秒数
    formatTime(time) {
      this.hours = Math.floor(time / 3600)
      this.minute = Math.floor(Math.floor(time % 3600) / 60)
      this.second = time % 60
      this.hours =
        this.hours.toString().length === 1 ? `0${this.hours}` : this.hours
      this.minute =
        this.minute.toString().length === 1 ? `0${this.minute}` : this.minute
      this.second =
        this.second.toString().length === 1 ? `0${this.second}` : this.second
      return this.hours + '时' + this.minute + '分' + this.second + '秒'
    }
  }
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM