首页 > Web开发 > 详细

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

时间:2020-02-19 16:30:38      阅读:135      评论:0      收藏:0      [点我收藏+]
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 + ‘秒‘
    }
  }
}

 

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

原文:https://www.cnblogs.com/maxiansheng/p/12331746.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!