获取当前显示的日期 2021年6月1日 星期二

dateTime() {
let time = new Date();
let year = time.getFullYear();
let month = time.getMonth() + 1;
let date = time.getDate();
let day = time.getDay();
let period;
switch (day) {
case 0:
period = "日";
break;
case 1:
period = "一";
break;
case 2:
period = "二";
break;
case 3:
period = "三";
break;
case 4:
period = "四";
break;
case 5:
period = "五";
break;
case 6:
period = "六";
break;
}
return `${year}年${month}月${date}日 星期${period}`;
},

获取昨天显示的日期 2019-10-13

function getDay(num,) {
var today = new Date();
var nowTime = today.getTime();
var ms = 24*3600*1000*num;
today.setTime(parseInt(nowTime + ms));
var oYear = today.getFullYear();
var oMoth = (today.getMonth() + 1).toString();
if (oMoth.length <= 1) oMoth = '0' + oMoth;
var oDay = today.getDate().toString();
if (oDay.length <= 1) oDay = '0' + oDay;
return oYear + str + oMoth + str + oDay;
}
var yesterday = getDay(-1, '-');
var today = getDay(0, '-');
console.log(yesterday,today);