Java Calendar Different getMonthDiff(Calendar c1, Calendar c2)

Here you can find the source of getMonthDiff(Calendar c1, Calendar c2)

Description

get Month Diff

License

LGPL

Declaration

public static int getMonthDiff(Calendar c1, Calendar c2) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import java.util.Calendar;

public class Main {
    public static int getMonthDiff(Calendar c1, Calendar c2) {

        int mon1 = c1.get(Calendar.MONTH);
        int mon2 = c2.get(Calendar.MONTH);

        int y1 = c1.get(Calendar.YEAR);
        int y2 = c2.get(Calendar.YEAR);

        return (y2 - y1) * 12 + mon2 - mon1;
    }/*from ww  w.ja  v a  2 s  .  co m*/
}

Related

  1. getDifferenceInDays(Calendar fromDate, Calendar toDate)
  2. getDifferenceInSeconds(Calendar calendarStart, Calendar calendarEnd)
  3. getDiffPartialYears(Date date, GregorianCalendar b)
  4. getDiffTargetDate(Calendar cal, int diffDay)
  5. getMillisDiff(long lhs, long rhs, int gregorianCalendarUnits)
  6. getMonthsDifference(Calendar date1, Calendar date2)
  7. getTargetDate(Calendar reqCal, int diffMon, int proxyDay)
  8. getTimeDifference(String unit, Calendar start, Calendar end)
  9. getTimeDiffSecond(Calendar first, Calendar second)