Java Date Before getPassedMonthBetweenDate(Date before, Date after)

Here you can find the source of getPassedMonthBetweenDate(Date before, Date after)

Description

get Passed Month Between Date

License

Open Source License

Declaration

public static int getPassedMonthBetweenDate(Date before, Date after) 

Method Source Code


//package com.java2s;

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

public class Main {

    public static int getPassedMonthBetweenDate(Date before, Date after) {
        Calendar c1 = Calendar.getInstance();
        Calendar c2 = Calendar.getInstance();

        c1.setTime(after);/*from   w  w w  . ja v  a 2 s  .c  o m*/
        c2.setTime(before);

        int result = c2.get(Calendar.MONTH) - c1.get(Calendar.MONTH);

        return result == 0 ? 1 : Math.abs(result);
    }
}

Related

  1. getMinuteBefore(Date date, int minute)
  2. getMonth(Date time, int monthBefore, int monthAfter)
  3. getMonthBefore(Date currentDate, int numberMonthBefore)
  4. getMonthStartDateBeforeCurrent(int monthNum, Date current)
  5. getOneHourBefore(Date date)
  6. getPreviousDate(String before)
  7. getQuarterStartDateBeforeCurrent(int num, Date current)
  8. getSomeDaysBeforeAfter(Date date, int days)
  9. isAtLeastOneDayBefore(Date daybefore, Date dayafter)