vue elementui 表格数据 时间格式转换
vue elementui 表格 中 时间数据格式转换
·
安装moment依赖库
<el-table-column
prop="uploadTime"
label="上传时间"
:formatter="formatTime"
width="180">
</el-table-column>
JS方法中实现
methods:{
//格式化时间
formatTime(row, column){
let date = row[column.property];
if(date === undefined){
return ''}
return moment(date).format("YYYY-MM-DD HH:mm:ss")
}
第二种方法,采用elementui自带的时间转换格式 亲测有效
<el-table-column
prop="uploadTime"
label="上传时间"
:formatter="formatTime"
width="180">
</el-table-column>
methods方法中实现时间转换函数
formatTime(row,column){
let data = row[column.property]
let dtime = new Date(data)
const year = dtime.getFullYear()
let month = dtime.getMonth() + 1
if (month < 10) {
month = '0' + month
}
let day = dtime.getDate()
if (day < 10) {
day = '0' + day
}
let hour = dtime.getHours()
if (hour < 10) {
hour = '0' + hour
}
let minute = dtime.getMinutes()
if (minute < 10) {
minute = '0' + minute
}
let second = dtime.getSeconds()
if (second < 10) {
second = '0' + second
}
return year+ '-' + month+ '-' + day + ' ' + hour + ':' + minute + ':' + second
}
上述方法如果还是无效 请检查linux服务器的时区
centos服务器设置时区 命令行
# timedatectl
# tzselect -select a time zone
# timedatectl set-timezone Asia/Shanghai
# timedatectl status
更多推荐



所有评论(0)