Here you can find the source of calculateMonthIn(Date date1, Date date2)
public static int calculateMonthIn(Date date1, Date date2)
//package com.java2s; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; public class Main { public static int calculateMonthIn(Date date1, Date date2) { Calendar cal1 = new GregorianCalendar(); cal1.setTime(date1);/*from w w w. j av a2 s . co m*/ Calendar cal2 = new GregorianCalendar(); cal2.setTime(date2); int c = (cal1.get(Calendar.YEAR) - cal2.get(Calendar.YEAR)) * 12 + cal1.get(Calendar.MONTH) - cal2.get(Calendar.MONTH); return Math.abs(c); } }