1.利用moment 格式化时间
import moment from 'moment'
// 2. 定义过滤器, 编写内部代码
filters: {
formatDate (val){
return moment(val).format('YYYY-MM-DD')
}
}
2 .自己写个过滤器
// 过滤器
Vue.filter("dateFormat", dtStr => {
const dt = new Date(dtStr);
const y = dt.getFullYear();
const m = padZero(dt.getMonth() + 1);
const d = padZero(dt.getDate());
const hh = padZero(dt.getHours());
const mm = padZero(dt.getMinutes());
const ss = padZero(dt.getSeconds());
return `${y}-${m}-${d} ${hh}:${mm}:${ss}`;
});
// 补零函数
function padZero(n) {
return n > 9 ? n : "0" + n;
}