Java Date to Month getMonthInterval(Date _one, Date _two)

Here you can find the source of getMonthInterval(Date _one, Date _two)

Description

get Month Interval

License

Open Source License

Declaration

public static int getMonthInterval(Date _one, Date _two) 

Method Source Code

//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);
    }
}

Related

  1. getMonthBetween(Date data1, Date data2)
  2. getMonthByOffset(Date date, int offset)
  3. getMonthDays(String date)
  4. getMonthFirstDay(Date date)
  5. getMonthFromDate(Date date)
  6. getMonthLastDate(Date date)
  7. getMonthLastDay(Date date)
  8. getMonthlyKey(Date d)
  9. getMonthName(Date date)