Java Day End getMonthBetween(Date startDate, Date endDate)

Here you can find the source of getMonthBetween(Date startDate, Date endDate)

Description

get Month Between

License

Apache License

Declaration

public static final Integer getMonthBetween(Date startDate, Date endDate) 

Method Source Code

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

Related

  1. getEndTimeOfDayOrNow(Date date)
  2. getKalenderWoche(final Date date, final Locale locale)
  3. getLastDayEnding(Date date, int field)
  4. getMinllisBetween(Date beginDate, Date endDate)
  5. getMondays(Date startDate, Date endDate)
  6. getMonthCha(Date start, Date end)
  7. getMonthCount(Date startDate, Date endDate)
  8. getMonthEnd(Date date)
  9. getMonthEndDate(Date date)