Java Day End getNumberOfMonthsBetween(final Date begin, final Date end)

Here you can find the source of getNumberOfMonthsBetween(final Date begin, final Date end)

Description

get Number Of Months Between

License

Open Source License

Declaration

public static int getNumberOfMonthsBetween(final Date begin, final Date end) 

Method Source Code

//package com.java2s;

import java.util.Calendar;
import java.util.Date;

public class Main {

    public static int getNumberOfMonthsBetween(final Date begin, final Date end) {
        if (begin == null || end == null)
            return -1;
        Calendar cal1 = Calendar.getInstance();
        cal1.setTime(begin);//from www.jav  a 2  s  . c  o  m
        Calendar cal2 = Calendar.getInstance();
        cal2.setTime(end);
        return (cal2.get(Calendar.YEAR) - cal1.get(Calendar.YEAR)) * 12
                + (cal2.get(Calendar.MONTH) - cal1.get(Calendar.MONTH));
    }
}

Related

  1. getMonthSpan(Date start, Date end)
  2. getMsBetween(Date startDate, Date endDate)
  3. getNextEndDate(Date date, int offset)
  4. getNextSendTime(Date sendDate, Date start)
  5. getNumberOfDaysBetweenDates(Date beginDate, Date endDate)
  6. getNumMonths(Date dStart, Date dEnd)
  7. getNumYears(Date dStart, Date dEnd)
  8. getSCDEndDate()
  9. getSecondSemesterEndDate(Integer year)