JS 实现前天昨天今天明天后天大后天

function GetDateStr(AddDayCount) {
var dd = new Date();
dd.setDate(dd.getDate() + AddDayCount); //获取AddDayCount天后的日期 
var y = dd.getFullYear();
var m = dd.getMonth() + 1; //获取当前月份的日期 
var d = dd.getDate();
return y + "-" + m + "-" + d;
}
document.write("前天:" + GetDateStr(-2));
document.write("<br />昨天:" + GetDateStr(-1));
document.write("<br />今天:" + GetDateStr(0));
document.write("<br />明天:" + GetDateStr(1));
document.write("<br />后天:" + GetDateStr(2));
document.write("<br />大后天:" + GetDateStr(3));

 

posted @ 2021-01-14 09:32  幸运(● ̄(エ) ̄●)  阅读(106)  评论(1编辑  收藏  举报
Document