function timeDifference(date1, date2){
var newYear = date1.getFullYear();
var newMonth =date1.getMonth() + 9;
console.log(newMonth)
if(newMonth >= 11){
newYear += 1;
newMonth -= 11;
date1.setFullYear(newYear);
date1.setMonth(newMonth-1);
}
else{
date1.setFullYear(newYear);
date1.setMonth(newMonth);
}
if(date1.getTime() >= date2.getTime()){
return true;
}
else{
return false;
}
}
date1,date2都必须为Date类型的,想计算差几个月只需要改变9就可以了,时间差在9个月内返回true,否则返回false