Here you can find the source of differenceMonth(Date date1, Date date2)
public static int differenceMonth(Date date1, Date date2)
//package com.java2s; import java.util.Calendar; import java.util.Date; import java.util.TimeZone; public class Main { private static TimeZone timeZone = TimeZone.getTimeZone("Asia/Tokyo"); public static int differenceMonth(Date date1, Date date2) { Calendar cal1 = Calendar.getInstance(timeZone); cal1.setTime(date1);/*w ww.j a v a2s . co m*/ cal1.set(Calendar.DATE, 1); Calendar cal2 = Calendar.getInstance(timeZone); cal2.setTime(date2); cal2.set(Calendar.DATE, 1); int count = 0; if (cal1.before(cal2)) { while (cal1.before(cal2)) { cal1.add(Calendar.MONTH, 1); count--; } } else { count--; while (!cal1.before(cal2)) { cal1.add(Calendar.MONTH, -1); count++; } } return count; } }