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("昨天:" + GetDateStr( - 1));
document.write("今天:" + GetDateStr(0));
document.write("明天:" + GetDateStr(1));
document.write("后天:" + GetDateStr(2));
document.write("大后天:" + GetDateStr(3));
效果图: