Here you can find the source of dateDiffMonth(Date d1, Date d2)
public static long dateDiffMonth(Date d1, Date d2)
//package com.java2s; //License from project: Apache License import java.util.Calendar; import java.util.Date; public class Main { public static long dateDiffMonth(Date d1, Date d2) { Calendar calendar = Calendar.getInstance(); calendar.setTime(d1);/*from w w w . j av a 2 s. c o m*/ int y1 = calendar.get(Calendar.YEAR); int m1 = calendar.get(Calendar.MONTH); calendar.setTime(d2); int y2 = calendar.get(Calendar.YEAR); int m2 = calendar.get(Calendar.MONTH); return (y1 - y2) * 12 + m1 - m2; } public static int get(Date date, int field) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); return calendar.get(field); } }