vue中时间戳转时间

vue2.0的Element UI的表格table列时间戳格式化

页面

formatter="formatDate"绑定一个 formatDate方法   

 

 方法

 

 

 (如果时间戳是10位数 需要乘以1000 13位数就不用)

 formatDate(row, column) {
      var date = new Date(row[column.property] * 1000)
      const Y = date.getFullYear() + '-'
      const M = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) + '-' : date.getMonth() + 1 + '-'
      const D = date.getDate() < 10 ? '0' + date.getDate() + ' ' : date.getDate() + ' '
      const h = date.getHours() < 10 ? '0' + date.getHours() + ':' : date.getHours() + ':'
      const m = date.getMinutes() < 10 ? '0' + date.getMinutes() + ':' : date.getMinutes() + ':'
      const s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
      return Y + M + D + h + m + s
    }

 

posted @ 2022-04-08 14:37  tomingto  阅读(1379)  评论(0编辑  收藏  举报