Original source http://hi.baidu.com/tonlywang/item/685fba8933a2a756e73d1950
One, date minus days equals second date function cc (DD,DADD) ... {//Can be added with error handling var a = new Date (dd) a = a.valueof () A = A-dadd * $ * 1000a = new Date (a) alert (a.getfullyear () + "year" + (A.getmonth () + 1) + "month" + a.getdate () + "Day")}cc ("12/23/2002", 2) here have to add, waste a lot of time to learn: Javascript code for time 0-11 numbers for January-December: VA The R a= new Date (2006,5,6) result is a 2006-6-60-6 that represents the day of the week 1-31 for 0-23 hours 0-59 minutes, and two seconds. Two-date difference (D1-D2). function DateDiff (D1,D2) {var day = $ x *1000;try{var Datearr = d1.split ("-"); var checkdate = new Date (); Checkdate.setfullyear (Datearr[0], datearr[1]-1, datearr[2]); var checktime = Checkdate.gettime (); var dateArr2 = D2.split ("-"); var checkDate2 = new Date (); Checkdate2.setfullyear (Datearr2[0], datearr2[1]-1, datearr2[2]); var checkTime2 = Checkdate2.gettime (); var cha = (checktime-checktime2)/day; return cha; }catch (e) {return false;}} End Fun III, application:<Scriptlanguage= "JavaScript"type= "Text/javascript">varFlag=Array ();//Global VariablesvarStart= "2009-01-01";varEnd= "2009-02-24"; Setflag (Start,end); for(varI=0; I<flag.length; I++) {document.write (Flag[i]+"\n\r");}//Set the date (array) within the periodfunctionSetflag (start,end) {varCDate=Array (); CDate=Start.split ("-");varCD=cdate[1]+"/"+cdate[2]+"/"+cdate[0]; varDaynum=DateDiff (end,start); for(varI=0; I<=daynum; I++) {Flag.push (AddDays (Cd,i));}}//End Fun//date plus the new date after the number of days.functionAddDays (date,days) {varnd= Newdate (date); nd=nd.valueof (); nd=nd+ Days* - * - * - * +; nd= NewDate (ND); //alert (nd.getfullyear () + "year" + (Nd.getmonth () + 1) + "month" + nd.getdate () + "Day");vary=nd.getfullyear ();varm=Nd.getmonth ()+1;varD=nd.getdate ();if(M<= 9) M= "0"+m;if(d<= 9) d= "0"+D;varCDate=y+"-"+m+"-"+D;returnCDate;}//the difference of two dates (D1-D2).functionDateDiff (d1,d2) {var Day= - * - * - * +;Try{ varDatearr=D1.split ("-"); varcheckdate= NewDate (); Checkdate.setfullyear (datearr[0], datearr[1]-1, datearr[2]); varChecktime=Checkdate.gettime (); varDATEARR2=D2.split ("-"); varCheckDate2= NewDate (); Checkdate2.setfullyear (datearr2[0], datearr2[1]-1, datearr2[2]); varcheckTime2=Checkdate2.gettime (); varCha=(Checktime-checkTime2)/Day ; returncha; }Catch(e) {return false;}}//End Fun</Script>#javascript小功能模块