// 日期格式化(xxxx年xx月xx日星期x)
dateFormat(time) {
let year = new Date(time).getFullYear();
let month = new Date(time).getMonth() + 1 < 10 ? '0' + (new Date(time).getMonth() + 1) : new Date(time).getMonth() + 1;
let date = new Date(time).getDate() < 10 ? '0' + new Date(time).getDate() : new Date(time).getDate();
let hh = new Date(time).getHours() < 10 ? '0' + new Date(time).getHours() : new Date(time).getHours();
let mm = new Date(time).getMinutes() < 10 ? '0' + new Date(time).getMinutes() : new Date(time).getMinutes();
let ss = new Date(time).getSeconds() < 10 ? '0' + new Date(time).getSeconds() : new Date(time).getSeconds();
let week = new Date(time).getDay();
let weeks = ['日', '一', '二', '三', '四', '五', '六'];
let getWeek = '星期' + weeks[week];
return year + '年' + month + '月' + date + '日,' + getWeek;
},
如何调用
<div class="showTime">今天是 {{ dateFormat(date) }}</div>
在data里面定义
date: new Date()