表格中封装一个时间处理函数
// 时间格式化
dateFormat1(row, column, cellValue, index) {
const daterc = row[column.property]
if (daterc != null) {
var date = new Date(daterc)
var year = date.getFullYear()
/* 在日期格式中,月份是从0开始,11结束,因此要加0
* 使用三元表达式在小于10的前面加0,以达到格式统一 如 09:11:05
* */
var month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
var day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
var hours = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
var minutes = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
var seconds = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
// 拼接
return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds
// return year + '-' + month + '-' + day + ' '
}
},
<el-table-column label="序号" type="index" />
<el-table-column label="姓名" prop="username" />
<el-table-column label="手机号" prop="mobile" />
<el-table-column label="聘用形式" prop="formOfEmployment" :formatter="formatEmployeeEnum" />
<el-table-column label="部门" prop="departmentName" />
<el-table-column label="入职时间" prop="correctionTime"` :formatter="dateFormat1" `sortable />
<el-table-column label="操作" width="280">
<template slot-scope="scope">
<el-button type="text" size="small">查看</el-button>
<el-button type="text" size="small">分配角色</el-button>
<el-button type="text" size="small" @click="hDel(scope.row.id)">删除</el-button>
</template>
</el-table-column>
</el-table>