html
<td>{{serverInfo.serverTime| formatTime('YMDHMS')}}</td>
js
serverTime: new Date().getTime(),
filters: {
// 时间过滤器
formatTime: function(value, type) {
let dataTime = "";
let data = new Date();
data.setTime(value);
let year = data.getFullYear();
let month = data.getMonth() + 1;
let day = data.getDate();
let hour = data.getHours();
let minute = data.getMinutes();
let second = data.getSeconds();
month < 10 ? (month = "0" + month) : month;
day < 10 ? (month = "0" + day) : day;
hour < 10 ? (hour = "0" + hour) : hour;
minute < 10 ? (minute = "0" + minute) : minute;
second < 10 ? (second = "0" + second) : second;
if (type == "YMD") {
dataTime = year + "-" + month + "-" + day;
} else if (type == "YMDHMS") {
dataTime =
year +
"-" +
month +
"-" +
day +
" " +
hour +
":" +
minute +
":" +
second;
} else if (type == "HMS") {
dataTime = hour + ":" + minute + ":" + second;
} else if (type == "YM") {
dataTime = year + "-" + month + "-";
}
return dataTime; // 将格式化后的字符串输出到前端显示
}
},