Java Utililty Methods Month Difference

List of utility methods to do Month Difference

Description

The list of methods to do Month Difference are organized into topic(s).

Method

intgetDiffBetweenMonth(Date latestDate, Date current)
get Diff Between Month
Calendar calCurrent = Calendar.getInstance();
calCurrent.setTime(current);
Calendar calLatest = Calendar.getInstance();
calLatest.setTime(latestDate);
if (calCurrent.get(Calendar.YEAR) - calLatest.get(Calendar.YEAR) > 0) {
    int diff = calCurrent.get(Calendar.YEAR) - calLatest.get(Calendar.YEAR);
    return (12 - (calLatest.get(Calendar.MONTH) + 1) + 1) + calCurrent.get(Calendar.MONTH)
            + 12 * (diff - 1);
...
intgetDiffMonth(Date begin, Date end)
get Diff Month
Calendar bc = Calendar.getInstance();
bc.setTimeInMillis(begin.getTime());
Calendar be = Calendar.getInstance();
be.setTime(end);
int beginYear = bc.get(Calendar.YEAR);
int beginMonth = bc.get(Calendar.MONTH);
int endYear = be.get(Calendar.YEAR);
int endMonth = be.get(Calendar.MONTH);
...
intgetDiffMonth(Date start, Date end)
get Diff Month
Calendar startCalendar = Calendar.getInstance();
startCalendar.setTime(start);
Calendar endCalendar = Calendar.getInstance();
endCalendar.setTime(end);
return (endCalendar.get(Calendar.YEAR) - startCalendar.get(Calendar.YEAR)) * 12
        + endCalendar.get(Calendar.MONTH) - startCalendar.get(Calendar.MONTH);
intgetDiffMonths(Date date1, Date date2)
get Diff Months
Calendar c1 = Calendar.getInstance();
Calendar c2 = Calendar.getInstance();
c1.setTime(date1);
if (date2 == null)
    c2.setTime(new java.util.Date());
else
    c2.setTime(date2);
int year1 = c1.get(Calendar.YEAR);
...