// 格式化时间 formatStr='yyyy-mm-dd h:i:s'
formatTime: function (time, formatStr){
let d = null;
if (time instanceof Date) {
d = time;
} else {
d = new Date(parseInt(time));
}
return formatStr.replace(/[a-z]+/g, (res) => {
switch (res.toLowerCase()) {
case 'yyyy':
return d.getFullYear();
case 'yy':
return d.getFullYear().toString().substr(2, 2);
case 'mm':
return zeroize(getMonth(d));
case 'm':
return getMonth(d);
case 'dd':
return zeroize(d.getDate());
case 'd':
return d.getDate();
case 'h':
return zeroize(d.getHours());
case 'i':
return zeroize(d.getMinutes());
case 's':
return zeroize(d.getSeconds());
}
});
},
function zeroize (value) {
if (value.toString().length === 1) {
return '0' + value;
} else {
return value;
}
}
function getMonth (d) {
let month = d.getMonth();
if (month == 12) {
month = 1;
} else {
month += 1;
}
return month;
}