js获取最近几天的日期

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>js获取日期:前天、昨天、今天、明天、后天 </title>
</head>
<body>
<script language="JavaScript" type="text/javascript">
Date.prototype.DateAdd = function(strInterval, Number)
{
var dtTmp = this;
switch (strInterval) {
case ‘s‘ :return new Date(Date.parse(dtTmp) + (1000 * Number));
case ‘n‘ :return new Date(Date.parse(dtTmp) + (60000 * Number));
case ‘h‘ :return new Date(Date.parse(dtTmp) + (3600000 * Number));
case ‘d‘ :return new Date(Date.parse(dtTmp) + (86400000 * Number));
case ‘w‘ :return new Date(Date.parse(dtTmp) + ((86400000 * 7) * Number));
case ‘q‘ :return new Date(dtTmp.getFullYear(), (dtTmp.getMonth()) + Number*3, dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds());
case ‘m‘ :return new Date(dtTmp.getFullYear(), (dtTmp.getMonth()) + Number, dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds());
case ‘y‘ :return new Date((dtTmp.getFullYear() + Number), dtTmp.getMonth(), dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds());
}
}
function GetDateStr2(AddDayCount)
{
var dd = new Date();
ddd = dd.DateAdd(‘d‘,AddDayCount);//三天后
var m = ddd.getMonth()+1;//获取当前月
var d = ddd.getDate();
return m+"-"+d;
}
document.write("前天:"+GetDateStr2(-2));
document.write("<br />昨天:"+GetDateStr2(-1));
document.write("<br />今天:"+GetDateStr2(0));
document.write("<br />明天:"+GetDateStr2(1));
document.write("<br />后天:"+GetDateStr2(2));
document.write("<br />大后天:"+GetDateStr2(3));
</script>
</body>
</html>

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。