Here you can find the source of diffBetweenMonth(Date d1, Date d2)
public static Long diffBetweenMonth(Date d1, Date d2)
//package com.java2s; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; public class Main { public static Long diffBetweenMonth(Date d1, Date d2) { Calendar cal1 = new GregorianCalendar(); cal1.setTime(d1);//from w ww. j av a 2 s .c o m Calendar cal2 = new GregorianCalendar(); cal2.setTime(d2); long month = (cal2.get(Calendar.YEAR) - cal1.get(Calendar.YEAR)) * 12 + cal2.get(Calendar.MONTH) - cal1.get(Calendar.MONTH); return month; } }