// 定义格式化封装函数
formaData() {
let timer = new Date();
const year = timer.getFullYear();
const month = timer.getMonth() + 1; // 由于月份从0开始,因此需加1
const day = timer.getDate();
const hour = timer.getHours();
const minute = timer.getMinutes();
const second = timer.getSeconds();
return `${this.pad(year, 4)}-${this.pad(month)}-${this.pad(day)} ${this.pad(hour)}:${this.pad(
minute
)}:${this.pad(second)}`;
},
// 定义具体处理标准
// timeEl 传递过来具体的数值:年月日时分秒
// total 字符串总长度 默认值为2
// str 补充元素 默认值为"0"
pad(timeEl, total = 2, str = "0") {
return timeEl.toString().padStart(total, str);
},