public static long subMonths ( final Date date1 , final Date date2 ) { Calendar calendar1 = buildCalendar ( date1 ) ; int monthOfDate1 = calendar1 . get ( Calendar . MONTH ) ; int yearOfDate1 = calendar1 . get ( Calendar . YEAR ) ; Calendar calendar2 = buildCalendar ( date2 ) ; int monthOfDate2 = calendar2 . get ( Calendar . MONTH ) ; int yearOfDate2 = calendar2 . get ( Calendar . YEAR ) ; int subMonth = Math . abs ( monthOfDate1 - monthOfDate2 ) ; int subYear = Math . abs ( yearOfDate1 - yearOfDate2 ) ; return subYear * 12 + subMonth ; }
Get how many months between two date .