Java Date Difference diffBetweenMonth(Date d1, Date d2)

Here you can find the source of diffBetweenMonth(Date d1, Date d2)

Description

diff Between Month

License

Open Source License

Declaration

public static Long diffBetweenMonth(Date d1, Date d2) 

Method Source Code

//package com.java2s;

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

public class Main {
    public static Long diffBetweenMonth(Date d1, Date d2) {
        Calendar cal1 = new GregorianCalendar();
        cal1.setTime(d1);//from   w  ww. j av  a  2 s .c o m
        Calendar cal2 = new GregorianCalendar();
        cal2.setTime(d2);
        long month = (cal2.get(Calendar.YEAR) - cal1.get(Calendar.YEAR)) * 12 + cal2.get(Calendar.MONTH)
                - cal1.get(Calendar.MONTH);
        return month;
    }
}

Related

  1. diff(Date endDate, Date startDate)
  2. diff(Date sDate, Date fDate)
  3. diff(Date subtrahend, Date minuend, long diffField)
  4. diff(int type, Date date1, Date date2)
  5. diff_in_date(Date d1, Date d2, String type)
  6. diffCommercial(Date dateUntil, Date dateFrom, boolean bAddDay)
  7. diffDate(Date date, Date date1)
  8. diffDate(java.util.Date date, java.util.Date date1)
  9. diffDateD(Date sd, Date ed)