Here you can find the source of getMonthBetween(Date startDate, Date endDate)
public static final Integer getMonthBetween(Date startDate, Date endDate)
//package com.java2s; //License from project: Apache License import java.util.Calendar; import java.util.Date; public class Main { public static final Integer getMonthBetween(Date startDate, Date endDate) { if (startDate == null || endDate == null || !startDate.before(endDate)) { return null; }//from w ww . j a v a2 s. com Calendar start = Calendar.getInstance(); start.setTime(startDate); Calendar end = Calendar.getInstance(); end.setTime(endDate); int year1 = start.get(Calendar.YEAR); int year2 = end.get(Calendar.YEAR); int month1 = start.get(Calendar.MONTH); int month2 = end.get(Calendar.MONTH); int n = (year2 - year1) * 12; n = n + month2 - month1; return n; } }