Project requirements: calculate the number of months between two months. If the number is less than, the calculation is based on one month. That is, the period from January 1 to January 2 is two months, and the period from January 1 to January 1 is one month, find some information from the Internet, join your own needs, and write your own js method, which is provided for your reference, such as the start date... syntaxHighlighter. all ();
Project requirements: calculate the number of months between two months. If the number is less than, the calculation is based on one month. That is, the period from January 1 to January 2 is two months, and the period from January 1 to January 1 is one month, find some information from the Internet, join your own needs, and write your own js method, which is provided for your reference. For example, the start date is 20110801 and the end date is 20110902.
Java code
Function setRateValidity (){
Var beginDate = document. getElementById ("crlimit: beginDate"). value;
Var endDate = document. getElementById ("crlimit: endDate"). value;
If (beginDate! = "" & EndDate! = "" & EndDate> = beginDate & (endDate-beginDate) <= 10000 ){
Var startDate = new Date (beginDate. substr (), beginDate. substr ()-1, beginDate. substr (); // The month starts from 0.
Var startDateUTC = Date. UTC (startDate. getFullYear (), startDate. getMonth (), startDate. getDate ());
Var end = new Date (endDate. substr (), endDate. substr ()-1, endDate. substr ));
Var endDateUTC = Date. UTC (end. getFullYear (), end. getMonth (), end. getDate (); var workmonthnum = 0;
For (var I = startDateUTC; I <= endDateUTC; I = I + 86400000 ){
Var days = new Date (I );
If (days. getDate () = 1 ){
Workmonthnum ++;
}
}
If (beginDate. substr (6, 2) = '01' & endDate. substr (6, 2) = '01 '){
Workmonthnum = workmonthnum-1;
}
If (beginDate. substr () = endDate. substr () & beginDate. substr () = endDate. substr )){
Workmonthnum = 1;
}
Document. getElementById ("crlimit: rateValidity"). value = workmonthnum;
}
}
Author "weidongke123-126-com"