Here you can find the source of getMonths(Date end, Date start)
public static int getMonths(Date end, Date start)
//package com.java2s; //License from project: Open Source License import java.util.Calendar; import java.util.Date; public class Main { public static int getMonths(Date end, Date start) { Calendar aCalendar = Calendar.getInstance(); Calendar bCalendar = Calendar.getInstance(); aCalendar.setTime(end);/*from ww w.j av a2s . c o m*/ bCalendar.setTime(start); int months = 0; while (aCalendar.before(bCalendar)) { months++; aCalendar.add(Calendar.MONTH, 1); } if (months == 0) { aCalendar.setTime(start); bCalendar.setTime(end); while (aCalendar.before(bCalendar)) { months++; aCalendar.add(Calendar.MONTH, 1); } } return months; } }