timeFormats(value, format) {
let result = "";
let date = new Date(value);
let year = date.getFullYear(); //年
let month = date.getMonth() + 1; //月
let day = date.getDate(); //日
let hour = date.getHours(); //时
let minutes = date.getMinutes(); //分
let seconds = date.getSeconds(); //秒
if (format == "yyyy-mm-dd") {
result = `${year}-${month < 10 ? "0" + month : month}-${
day < 10 ? "0" + day : day
}`;
} else if (format == "yyyy-mm") {
result = `${year}-${month < 10 ? "0" + month : month}`;
} else if (format == "yyyy") {
result = `${year}`;
} else {
result = `${year}-${month < 10 ? "0" + month : month}-${
day < 10 ? "0" + day : day
} ${hour < 10 ? "0" + hour : hour}:${
minutes < 10 ? "0" + minutes : minutes
}:${seconds < 10 ? "0" + seconds : seconds}`;
}
return result;
},
模板字符串:https://es6.ruanyifeng.com/?search=%60%24%28%29%60&x=3&y=4#docs/string(第5点)
知乎回答模板字符串:https://www.zhihu.com/question/48648714