Here you can find the source of getMonthSpan(Date begin, Date end)
public static int getMonthSpan(Date begin, Date end)
//package com.java2s; //License from project: Apache License import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; public class Main { public static int getMonthSpan(Date begin, Date end) { Calendar beginCal = new GregorianCalendar(); beginCal.setTime(begin);/*from w ww .ja va 2s .com*/ Calendar endCal = new GregorianCalendar(); endCal.setTime(end); int m = (endCal.get(Calendar.MONTH)) - (beginCal.get(Calendar.MONTH)); int y = (endCal.get(Calendar.YEAR)) - (beginCal.get(Calendar.YEAR)); return y * 12 + m; } }