Here you can find the source of getDiffMonth(Date begin, Date end)
public static int getDiffMonth(Date begin, Date end)
//package com.java2s; //License from project: Apache License import java.util.Calendar; import java.util.Date; public class Main { public static int getDiffMonth(Date begin, Date end) { Calendar bc = Calendar.getInstance(); bc.setTimeInMillis(begin.getTime()); //bc.setTime(begin.getTime()); Calendar be = Calendar.getInstance(); be.setTime(end);//from w ww . ja v a 2 s . c om int beginYear = bc.get(Calendar.YEAR); int beginMonth = bc.get(Calendar.MONTH); int endYear = be.get(Calendar.YEAR); int endMonth = be.get(Calendar.MONTH); int difMonth = (endYear - beginYear) * 12 + (endMonth - beginMonth); return difMonth; } }