vue中时间过滤器中的月日不足两位补0
先将月,和日转换为字符串,然后用字符串的padStrat(2,0)方法(两位,不足补0)
filters: {
handleData(date) {
const timeDate = new Date(date);
const year = timeDate.getFullYear();
const month = (timeDate.getMonth() + 1).toString().padStart(2, 0);
const day = timeDate.getDate().toString().padStart(2, 0);
const hour = timeDate.getHours().toString().padStart(2, 0);
const min = timeDate.getMinutes().toString().padStart(2, 0);
const s = timeDate.getSeconds().toString().padStart(2, 0);
return year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + s;
},
},