This article describes how to use JavaScript to calculate the date in two date periods, involving the time of javascript operations, for more information about how to use JavaScript to calculate dates in two date periods, see the following example. Share it with you for your reference. The specific implementation method is as follows:
The Code is as follows:
/*************************
* Calculate all dates in two date periods
*
* @ Param value1
* Start Date YYYY-MM-DD
* @ Param value2
* End Date
* Return date Array
*/
Function dataScope (value1, value2 ){
Var getDate = function (str ){
Var tempDate = new Date ();
Var list = str. split ("-");
TempDate. setFullYear (list [0]);
TempDate. setMonth (list [1]-1 );
TempDate. setDate (list [2]);
Return tempDate;
}
Var date1 = getDate (value1 );
Var date2 = getDate (value2 );
If (date1> date2 ){
Var tempDate = date1;
Date1 = date2;
Date2 = tempDate;
}
Date1.setDate (date1.getDate () + 1 );
Var dateArr = [];
Var I = 0;
While (! (Date1.getFullYear () = date2.getFullYear ()
& Amp; date1.getMonth () = date2.getMonth () & amp; date1.getDate () = date2
. GetDate ())){
Var dayStr = date1.getDate (). toString ();
If (dayStr. length = 1 ){
DayStr = "0" + dayStr;
}
DateArr [I] = date1.getFullYear () + "-" + (date1.getMonth () + 1) + "-"
+ DayStr;
I ++;
/*
* Document. write ("
"+ Date1.getFullYear () +
* "-" + (Date1.getMonth () + 1) + "-" + date1.getDate () +"
");
*/
// Document. write (dateArr [I] +"
");
Date1.setDate (date1.getDate () + 1 );
}
Return dateArr;
}
I hope this article will help you design javascript programs.