定时显示
mounted(){
setInterval(()=>{
this.dateFormat();
},1000)
},
实现时间格式的统一,小于10时前边加0格式如:08:05:09
dateFormat(){
const nowDate = new Date();
const date = {
year:nowDate.getFullYear(),
month:nowDate.getMonth()+1 < 10? "0" + (nowDate.getMonth() + 1):nowDate.getMonth() + 1,
date:nowDate.getDate() < 10 ? "0" +nowDate.getDate():nowDate.getDate(),
hour:nowDate.getHours()<10 ? "0" + nowDate.getHours():nowDate.getHours(),
minutes:nowDate.getMinutes()<10 ? "0" + nowDate.getMinutes():nowDate.getMinutes(),
seconds:nowDate.getSeconds()<10 ? "0" + nowDate.getSeconds():nowDate.getSeconds(),
weekDay : nowDate.getDay(),
}
const week = new Array(7);
week[0] = "星期日";
week[1] = "星期一";
week[2] = "星期二";
week[3] = "星期三";
week[4] = "星期四";
week[5] = "星期五";
week[6] = "星期六";
this.date = date.year + '-' + date.month + '-' + date.date + ' '+ week[date.weekDay] + ' ' + date.hour + ':' + date.minutes + ':' + date.seconds;
}