1.展示
2.代码
data() {
return {
newYear: "0000 年 00 月 00 日 ",
newTime: "00:00:00",
today: "",
timer: null, //时间定时器
};
},
created() {
this.getCurrentDate();
this.timer = setInterval(() => {
this.getCurrentDate();
}, 1000);
},
methods: {
getCurrentDate() {
let now = new Date();
let year = now.getFullYear();
let month = now.getMonth() + 1;
let day = now.getDate();
let index = now.getDay();
if(Cookies.get('language')==='zh-CN'){
this.newYear = year + "年" + month + "月" + day+ "日";
}else{
this.newYear= year + "-" + month + "-" + day;
}
this.newTime = now.toLocaleString().split(' ')[1];
let dayList= ["日", "一", "二", "三", "四", "五", "六"];
this.today = dayList[index];
},
}