Java Day End getMonthCount(Date startDate, Date endDate)

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

Description

Return month count.

License

Open Source License

Parameter

Parameter Description
startDate bounds start
endDate bounds end

Return

count of months. (if start month == end month, count = 1)

Declaration

public static int getMonthCount(Date startDate, Date endDate) 

Method Source Code


//package com.java2s;
import java.util.Calendar;
import java.util.Date;

public class Main {
    /**//from w  w w  .j av  a2  s.  c  o  m
     * Return month count.
     *
     * @param startDate bounds start
     * @param endDate bounds end
     * @return count of months. (if start month == end month, count = 1)
     */
    public static int getMonthCount(Date startDate, Date endDate) {

        int count = 1;
        Calendar calendar = Calendar.getInstance();

        calendar.setTime(endDate);
        count += calendar.get(Calendar.YEAR) * 12 + calendar.get(Calendar.MONTH);
        calendar.setTime(startDate);
        count -= calendar.get(Calendar.YEAR) * 12 + calendar.get(Calendar.MONTH);

        return count;
    }
}

Related

  1. getLastDayEnding(Date date, int field)
  2. getMinllisBetween(Date beginDate, Date endDate)
  3. getMondays(Date startDate, Date endDate)
  4. getMonthBetween(Date startDate, Date endDate)
  5. getMonthCha(Date start, Date end)
  6. getMonthEnd(Date date)
  7. getMonthEndDate(Date date)
  8. getMonthEndDate(int year, int month)
  9. getMonthEndDate(Long day)