Here you can find the source of getNumberOfMonthsBetween(final Date begin, final Date end)
public static int getNumberOfMonthsBetween(final Date begin, final Date end)
//package com.java2s; import java.util.Calendar; import java.util.Date; public class Main { public static int getNumberOfMonthsBetween(final Date begin, final Date end) { if (begin == null || end == null) return -1; Calendar cal1 = Calendar.getInstance(); cal1.setTime(begin);//from www.jav a 2 s . c o m Calendar cal2 = Calendar.getInstance(); cal2.setTime(end); return (cal2.get(Calendar.YEAR) - cal1.get(Calendar.YEAR)) * 12 + (cal2.get(Calendar.MONTH) - cal1.get(Calendar.MONTH)); } }