Java Date Calculate calculateMonthIn(Date date1, Date date2)

Here you can find the source of calculateMonthIn(Date date1, Date date2)

Description

calculate Month In

License

Open Source License

Declaration

public static int calculateMonthIn(Date date1, Date date2) 

Method Source Code

//package com.java2s;

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

public class Main {
    public static int calculateMonthIn(Date date1, Date date2) {
        Calendar cal1 = new GregorianCalendar();
        cal1.setTime(date1);/*from w w w. j av a2  s .  co m*/
        Calendar cal2 = new GregorianCalendar();
        cal2.setTime(date2);
        int c = (cal1.get(Calendar.YEAR) - cal2.get(Calendar.YEAR)) * 12 + cal1.get(Calendar.MONTH)
                - cal2.get(Calendar.MONTH);
        return Math.abs(c);
    }
}

Related

  1. calculateDays(Date startDate, Date endDate)
  2. calculateDurationEndInSec(Date start, int durationInSeconds)
  3. calculateEndDate(Date startDate, int duration)
  4. calculateGestationAge(Date today, Date edd)
  5. calculateLookbackDate(int lookback)
  6. calculateNextSettleDate(Date date, int addMonth)
  7. calculateOffsetFromGMT(Date date)
  8. calculatePastDate(int days)
  9. calculateTime(Date date, String addpart, int num)