Here you can find the source of getPassedMonthBetweenDate(Date before, Date after)
public static int getPassedMonthBetweenDate(Date before, Date after)
//package com.java2s; import java.util.Calendar; import java.util.Date; public class Main { public static int getPassedMonthBetweenDate(Date before, Date after) { Calendar c1 = Calendar.getInstance(); Calendar c2 = Calendar.getInstance(); c1.setTime(after);/*from w w w . ja v a 2 s .c o m*/ c2.setTime(before); int result = c2.get(Calendar.MONTH) - c1.get(Calendar.MONTH); return result == 0 ? 1 : Math.abs(result); } }