Here you can find the source of countMonths(java.util.Date startDate, java.util.Date endDate)
public static int countMonths(java.util.Date startDate, java.util.Date endDate) throws IllegalArgumentException
//package com.java2s; /**//from w w w . ja v a 2 s .com * Copyrights 2002-2011 Webb Fontaine * This software is the proprietary information of Webb Fontaine. * Its use is subject to License terms. * Developer: nigiyan * Date: 04/11/2011 */ import java.util.Calendar; public class Main { private static Calendar cal1 = Calendar.getInstance(); private static Calendar cal2 = Calendar.getInstance(); public static int countMonths(java.util.Date startDate, java.util.Date endDate) throws IllegalArgumentException { cal1.setTime(endDate); cal2.setTime(startDate); return ((cal1.get(Calendar.YEAR) - cal2.get(Calendar.YEAR)) * 12) + cal1.get(Calendar.MONTH) - cal2.get(Calendar.MONTH); } }