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 }