Here you can find the source of monthDiff(Date from, Date to)
public static int monthDiff(Date from, Date to)
//package com.java2s; import java.util.Calendar; import java.util.Date; public class Main { public static int monthDiff(Date from, Date to) { Calendar fromCal = Calendar.getInstance(); Calendar toCal = Calendar.getInstance(); fromCal.setTime(from);/*from w w w . ja v a 2 s . com*/ toCal.setTime(to); int monthDiff = (toCal.get(Calendar.YEAR) - fromCal.get(Calendar.YEAR)) * 12 + (toCal.get(Calendar.MONTH) - fromCal.get(Calendar.MONTH)); return monthDiff; } }