Java Day End getMonths(Date end, Date start)

Here you can find the source of getMonths(Date end, Date start)

Description

get Months

License

Open Source License

Declaration

public static int getMonths(Date end, Date start) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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

public class Main {

    public static int getMonths(Date end, Date start) {
        Calendar aCalendar = Calendar.getInstance();
        Calendar bCalendar = Calendar.getInstance();
        aCalendar.setTime(end);/*from ww  w.j av a2s .  c o  m*/
        bCalendar.setTime(start);
        int months = 0;
        while (aCalendar.before(bCalendar)) {
            months++;
            aCalendar.add(Calendar.MONTH, 1);
        }

        if (months == 0) {
            aCalendar.setTime(start);
            bCalendar.setTime(end);
            while (aCalendar.before(bCalendar)) {
                months++;
                aCalendar.add(Calendar.MONTH, 1);
            }
        }
        return months;
    }
}

Related

  1. getMonthEnd(Date date)
  2. getMonthEndDate(Date date)
  3. getMonthEndDate(int year, int month)
  4. getMonthEndDate(Long day)
  5. getMonthFirstDays(Date startDate, Date endDate)
  6. getMonthsBetweenBeginDateAndEndDate(Date beginDate, Date endDate)
  7. getMonthSpan(Date begin, Date end)
  8. getMonthSpan(Date start, Date end)
  9. getMsBetween(Date startDate, Date endDate)