1、在main.js中定义
// 格式化时间
Vue.filter('formatDate', function (value) {
let date = new Date(value);
let y = date.getFullYear();
let MM = date.getMonth() + 1 + "";
MM = parseInt(MM) < 10 ? "0" + MM : MM;
let d = date.getDate() + "";
d = parseInt(d) < 10 ? "0" + d : d;
let h = date.getHours() + "";
h = parseInt(h) < 10 ? "0" + h : h;
let m = date.getMinutes() + "";
m = parseInt(m) < 10 ? "0" + m : m;
let s = date.getSeconds() + "";
s = parseInt(s) < 10 ? "0" + s : s;
return y + "-" + MM + "-" + d + " " + h + ":" + m + ":" + s;
})
2、在组件中使用
<el-table-column property="lastUpdateTime" label="上次修改时间" width="180">
<template slot-scope="scope">
<i class="el-icon-time"></i>
<span style="margin-left: 10px">{{ scope.row.lastUpdateTime | formatDate }}</span>
</template>
</el-table-column>
结果:
2020-01-02 00:00:00