如题,谢谢
Date对象的构造方法就行....
new Date(year,month,day,hours,minutes,seconds,milseconds)
各个参数,你可以随便的怎么样传入数值型参数,Date对象会自己帮你计算好日期...
var dat = new Date();
new Date(dat.getFullYear()-1,dat.getMonth(),dat.getDate());
获得去年的今天这一天的日期...
<script >
Date.prototype.addDay=function (num)
{
this.setDate(this.getDate()+num);
return this;
}
Date.prototype.addMonth=function (num)
{
var tempDate=this.getDate();
this.setMonth(this.getMonth()+num);
if(tempDate!=this.getDate()) this.setDate(0);
return this;
}
Date.prototype.addYear=function (num)
{
var tempDate=this.getDate();
this.setYear(this.getYear()+num);
if(tempDate!=this.getDate()) this.setDate(0);
return this;
}
var d1;
d1=new Date(2004/02/29);
alert(d1.addYear(1));
d1=new Date(2004/01/31);
alert(d1.addMonth(1));
d1=new Date(2004/02/29);
alert(d1.addDay(1));
</script>