效果图,直接上代码
<el-table :data="tableData">
<el-table-column prop="activityTime" :formatter='activityTime' label="活动时间">
</el-table-column>
</el-table>
methods: {
formatDate (date) {
var date1 = new Date(date);
var myyear = date1.getFullYear();
var mymonth = date1.getMonth() + 1;
var myweekday = date1.getDate();
if (mymonth < 10) {
mymonth = "0" + mymonth;
}
if (myweekday < 10) {
myweekday = "0" + myweekday;
}
return myyear + "-" + mymonth + "-" + myweekday;
},
activityTime (row) {
const that = this; // 这个也是重点
if (row.startTime != null && row.endTime != null) {
return that.formatDate(row.startTime) + "/" + that.formatDate(row.endTime);
} else {
return "";
}
},
}
第二种:
<span>时间:</span><span>{{formateDateTime(row.creatime)}}</span>
methods: {
formateDateTime (value) {
if (value == null) {
return ''
} else {
let date = new Date(value)
let y = date.getFullYear() // 年
let MM = date.getMonth() + 1 // 月
MM = MM < 10 ? ('0' + MM) : MM
let d = date.getDate() // 日
d = d < 10 ? ('0' + d) : d
let h = date.getHours() // 时
// h = h < 10 ? ('0' + h) : h
// let m = date.getMinutes()// 分
// m = m < 10 ? ('0' + m) : m
// let s = date.getSeconds()// 秒
// s = s < 10 ? ('0' + s) : s
// return y + '-' + MM + '-' + d + ' ' + h + ':' + m + ':' + s
return y + '-' + MM + '-' + d
}
}
}
希望对你有用