<html>
<head>
<meta HTTP-equiv="Content-Type" content="textml; charset=utf-8">
<title>js獲取日期:前天、昨天、今天、明天、後天 - Liehuo.Net</title>
</head>
<body>
<script language="JavaScript" type="text/javascript">
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();
var a = new Array( "星期日","星期一", "星期二", "星期三", "星期四", "星期五", "星期六","星期日","星期一", "星期二", "星期三", "星期四", "星期五", "星期六","星期日");
var week = new Date().getDay()+AddDayCount;
var w = a[week];
return m+"月"+d+"日"+w;
}
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));
document.write("<br />後天:"+GetDateStr(4));
document.write("<br />大後天:"+GetDateStr(5));
document.write("<br />後天:"+GetDateStr(6));
document.write("<br />大後天:"+GetDateStr(7));
</script>
</body>
<ml>