时间戳转化事件格式

// 判断是否前面补0
    add0 (m) {
      return m < 10 ? '0' + m : m
    },
    // 时间转化
    timeFormat (timestamp) {
    // timestamp是整数,否则要parseInt转换,不会出现少个0的情况
      var time = new Date(timestamp)
      // var year = time.getFullYear()
      // var month = time.getMonth() + 1
      // var date = time.getDate()
      var hours = time.getHours()
      var minutes = time.getMinutes()
      var seconds = time.getSeconds()
      // return year + '-' + this.add0(month) + '-' + this.add0(date) + ' ' + this.add0(hours) + ':' + this.add0(minutes) + ':' + this.add0(seconds)
      return this.add0(hours) + ':' + this.add0(minutes) + ':' + this.add0(seconds)
    },

猜你喜欢

转载自www.cnblogs.com/zeng2210/p/8906247.html