Here you can find the source of getMonthInterval(Date _one, Date _two)
public static int getMonthInterval(Date _one, Date _two)
//package com.java2s; /*// w w w . jav a 2s. com * Copyright (c) 1999-2002 Erry Network Technology, Inc. All Rights Reserved. * * This software is the confidential and proprietary information of Erry * Network Technology, Inc. ("Confidential Information"). You shall not * disclose such Confidential Information and shall use it only in * accordance with the terms of the license agreement you entered into * with Erry. * * ERRY MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR * PURPOSE, OR NON-INFRINGEMENT. ERRY SHALL NOT BE LIABLE FOR ANY DAMAGES * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING * THIS SOFTWARE OR ITS DERIVATIVES. * * $Archive: /src/work/com/erry/its/model/tools/DateUtil.java $ $Revision: 1.2 $ */ import java.util.Calendar; import java.util.Date; public class Main { public static int getMonthInterval(Date _one, Date _two) { Calendar one = Calendar.getInstance(); one.setTime(_one); Calendar two = Calendar.getInstance(); two.setTime(_two); int yearInt = two.get(Calendar.YEAR) - one.get(Calendar.YEAR); int monthInt = two.get(Calendar.MONTH) - one.get(Calendar.MONTH); int dayInt = two.get(Calendar.DAY_OF_MONTH) - one.get(Calendar.DAY_OF_MONTH); return yearInt * 12 + monthInt + (dayInt > 0 ? 1 : 0); } }