1.网上找的时间戳方法,我单独放在一个js里
export function formatDate(timestamp) {
var date = new Date(timestamp * 1000);//时间戳为10位需*1000,时间戳为13位的话不需乘1000
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.在XX.vue组件引入进来
import {formatDate} from '@/assets/js/date.js'
3.为了方便使用,用了过滤器
filters:{
//时间戳
formatDate(time) {
return formatDate(time);
},
}
4.在列表中使用它(用了elementUI框架)
<el-table-column prop="createTime" label="CREATETIME" sortable>
<template slot-scope="scope">
{{ scope.row.createTime|formatDate }}
</template>
</el-table-column>
5.执行结果
这是怎么回事呀?
看看
scope.row.createTime
有没有问题。