1、安装
cnpm install dayjs -S
2、实现的效果
3、实现的代码
//先引入
var dayjs = require('dayjs');
//使用定时器每秒更新
setInterval(() => {
let tempData = dayjs(new Date()).format('YYYY年MM月DD日 HH:mm:ss');
let tempArr = tempData.split(' ');
this.dateData = tempArr[0];
this.timeData = tempArr[1];
let tempWeek = dayjs(new Date()).day();
switch (tempWeek) {
case 0:
this.weekData = '星期日';
break;
case 1:
this.weekData = '星期一';
break;
case 2:
this.weekData = '星期二';
break;
case 3:
this.weekData = '星期三';
break;
case 4:
this.weekData = '星期四';
break;
case 5:
this.weekData = '星期五';
break;
case 6:
this.weekData = '星期六';
break;
default:
this.weekData = '星期一';
break;
}
}, 1000);