function getMonths(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;
}
js怎样计算两个年月的月份差
最新推荐文章于 2024-08-03 11:36:34 发布