将后台返回的时间格式2020-09-25T07:06:35.000+00:00 格式化为YY-MM-DD HH:MM:SS
Vue中的时间格式化:
dateFormat(row, column, cellValue, index) {
const daterc = row[column.property];
if (daterc != null) {
const dateMat = new Date(daterc);
// console.log('77',dateMat);
// console.log('88',daterc.getFullYear());
const year = dateMat.getFullYear();
var month_;
var day_;
const month = dateMat.getMonth() + 1;
if (month < 10) {
month_ = "0" + month;
} else {
month_ = "" + month;
}
const day = dateMat.getDate();
if (day < 10) {
day_ = "0" + day;
} else {
day_ = "" + day;
}
const hh = dateMat.getHours() + "";
var hh_;
var mm_;
var ss_;
if (hh.length < 2) {
hh_ = "0" + hh;
} else {
hh_ = "" + hh;
}
const mm = dateMat.getMinutes() + "";
if (mm.length < 2) {
mm_ = "0" + mm;
} else {
mm_ = "" + mm;
}
const ss = dateMat.getSeconds() + "";
if (ss.length < 2) {
ss_ = "0" + ss;
} else {
ss_ = "" + ss;
}
const timeFormat =
year + "-" + month_ + "-" + day_ + " " + hh_ + ":" + mm_ + ":" + ss_;
return timeFormat;
}
},
<el-table-column
prop="registerTime"
label="注册时间"
:formatter="dateFormat"
width="160"
>
</el-table-column>
JS时间格式化:
readJsonDate(JsonDateValue) {
var o = new Date(JsonDateValue); //传进去最原始的时间数据即可
var h = o.getHours();
var m = o.getMinutes();
var s = o.getSeconds();
var y = o.getFullYear();
var M = o.getMonth() + 1;
var d = o.getDate();
h = this.checkTime(h);
m = this.checkTime(m);
s = this.checkTime(s);
M = this.checkTime(M);
d = this.checkTime(d);
o = y + "-" + M + "-" + d + " " + h + ":" + m + ":" + s;
return o;
},
checkTime(i) {
if (i < 10) {
i = "0" + i;
}
return i;
},
其实可以用第二种方式代替第一种,不过,已经写完了 就分享一下吧。。。