JS calculate difference in months between two months

// Calculate the month difference between two months
        var date1 = "" ;
        var date2 = "" ;
// split the year, month and day
date1 = date1.split('-');
// get the month number
date1 = parseInt( date1[0]) * 12 + parseInt(date1[1]);
// split year month day
date2 = date2.split('-');
// get month number
date2 = parseInt(date2[0]) * 12 + parseInt(date2[1]);
var m = Math.abs(date1 - date2);

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326272129&siteId=291194637