One, date minus days equals second date
function cc (DD,DADD) {
//can be added error handling
var a = new Date (dd)
a = a.valueof ()
a = a-dadd * * * * * 1000
a = new Date (a)
alert (a.getfullyear () + "year" + (A.getmonth () + 1) + "month" + a.getdate () + "Day")
}
cc ("12/23/200 2 ", 2)
Here we have to add, waste a lot of time to learn:
Javascript's code for TIME
0-11 number Expression January-December: Var a= new Date (2006,5,6) turns out to be 2006-6-6
0-6 means week
1-31 means date
0-23 hours
0-59 minutes, seconds.
Two. Two-date difference (D1-D2).
function DateDiff (D1,D2) {var day = * * *
*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
Third, the application:
<script language= "javascript" type= "Text/javascript" > var flag = Array ();//global variable var start = "2009-01-01";
var end = "2009-02-24";
Setflag (Start,end);
for (var i=0; i<flag.length; i++) {document.write (flag[i]+ "\n\r");} Set Date (array) function Setflag (start,end) {var cdate = array (); CDate = Start.split ("-"); var cd = cdate[1]+ "/" +cdate[2]+
"/" +cdate[0];
var daynum = DateDiff (End,start); for (var i=0; i<=daynum; i++) {Flag.push (AddDays (Cd,i));}
End fun//date plus days after the new date.
function AddDays (date,days) {var nd = new Date (date);
nd = nd.valueof ();
nd = nd + days * 24 * 60 * 60 * 1000;
nd = new Date (ND);
Alert (nd.getfullyear () + "year" + (Nd.getmonth () + 1) + "month" + nd.getdate () + "Day");
var y = nd.getfullyear ();
var m = nd.getmonth () +1;
var d = nd.getdate ();
if (M <= 9) m = "0" +M;
if (d <= 9) d = "0" +D;
var cdate = y+ "-" +m+ "-" +D;
return cdate;
}//Two-date difference (D1-D2).
function DateDiff (D1,D2) {var day = *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 </script>