js获取两个日期相差几天,相差几个月

//两个日期相差几天

dateMinus(dateStart, dateEnd) {
	var sdate = new Date(dateStart); 
     	var now = new Date(dateEnd); 
    	var days = now.getTime() - sdate.getTime(); 
     	var day = Math.floor(days / (1000 * 60 * 60 * 24)); 
      	
	return day;
}
//两个日期相差几个月
dateMinus(d1, d2) {
	var m1 = parseInt(d1.split("/")[1].replace(/^0+/, "")) + parseInt(d1.split("/")[0]) * 12;
             var m2 = parseInt(d2.split("/")[1].replace(/^0+/, "")) + parseInt(d2.split("/")[0]) * 12;
	var diff = m2 - m1;
	
	return diff;
}

你可能感兴趣的:(笔记)