多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
13位的时间戳转换可以用element-ui表格自带的:formatter函数,来格式化表格内容: 方法一:全局间戳转换10位和13位在函数里选择 ``` <el-table-column align="center" min-width="300" label="开始日"> <template slot-scope="scope"> {{scope.row.time_a | dataFormat}} </template> </el-table-column> // main.js里面设置全局时间过滤器 Vue.filter('dataFormat', function (originVal) { //const dt = new Date(originVal) const dt = newDate(parseInt(originVal + '000')) //必须转换成13位使用 const y = dt.getFullYear() const m = (dt.getMonth() + 1 + '').padStart(2, '0') const d = (dt.getDate() + '').padStart(2, '0') const hh = (dt.getHours() + '').padStart(2, '0') const mm = (dt.getMinutes() + '').padStart(2, '0') const ss = (dt.getSeconds() + '').padStart(2, '0') // yyyy-mm-dd hh:mm:ss return `${y}-${m}-${d} ${hh}:${mm}:${ss}` }) ``` 方法二:单个文件单个数据对应使用 ``` <el-table-column align="center" min-width="200" label="开始日" prop="time_a" :formatter="formatDate" /> //methods: //时间戳转换 时间戳为10位需*1000,时间戳为13位的话不需乘1000 formatDate (row, column) { const date = new Date(parseInt(row.time_a) * 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 }, ``` 方法三:装依赖之后在使用页面引入后使用 ``` http://momentjs.cn/ <el-table-column label="创建竞赛时间" min-width="120" prop="create_time" :formatter="dateForma"></el-table-column> 先安装依赖之后 import moment from "moment"; //单文件导入文件 //methods: //时间格式化转换 时间戳为10位 dateForma: function(row, column, data) { return moment.unix(data).format("YYYY-MM-DD HH:mm:ss"); }, ```