Here you can find the source of getDiffBetweenMonth(Date latestDate, Date current)
public static int getDiffBetweenMonth(Date latestDate, Date current)
//package com.java2s; //License from project: Apache License import java.util.Calendar; import java.util.Date; public class Main { public static int getDiffBetweenMonth(Date latestDate, Date current) { Calendar calCurrent = Calendar.getInstance(); calCurrent.setTime(current);//from w w w . jav a 2s . c om Calendar calLatest = Calendar.getInstance(); calLatest.setTime(latestDate); if (calCurrent.get(Calendar.YEAR) - calLatest.get(Calendar.YEAR) > 0) { int diff = calCurrent.get(Calendar.YEAR) - calLatest.get(Calendar.YEAR); return (12 - (calLatest.get(Calendar.MONTH) + 1) + 1) + calCurrent.get(Calendar.MONTH) + 12 * (diff - 1); } else { return calCurrent.get(Calendar.MONTH) - calLatest.get(Calendar.MONTH); } } }