//返回兩個日期相差的月數
function MonthsBetw(date1, date2) {
//用-分成數組
date1 = date1.split("-");
date2 = date2.split("-");
//獲取年,月數
var year1 = parseInt(date1[0]),
month1 = parseInt(date1[1]),
year2 = parseInt(date2[0]),
month2 = parseInt(date2[1]),
//通過年,月差計算月份差
months = (year2 - year1) * 12 + (month2 - month1) + 1;
return months;
}
