1. For the timestamp method found on the Internet, I put it separately in a js
export function formatDate(timestamp) {
var date = new Date(timestamp * 1000);//10*1000131000
Y = date.getFullYear() + "-";
M = (date.getMonth()+1 < 10 ? "0"+(date.getMonth()+1) : date.getMonth()+1) + "-";
D = date.getDate() + " ";
h = date.getHours() + ":";
m = date.getMinutes() + ":";
s = date.getSeconds();
return Y+M+D+h+m+s;
}
2. Introduce
into the XX.vue componentimport {formatDate} from "@/assets/js/date.js"
3. For ease of use, the filter
is used.filters:{
//
formatDate(time) {
return formatDate(time);
},
}
4. Use it in the list (using the elementUI framework)
<el-table-column prop="createTime" label="CREATETIME" sortable>
<template slot-scope="scope">
{{ scope.row.createTime|formatDate }}
</template>
</el-table-column>
5. Execution result
what"s going on?