Java Date Difference differenceOnYear(Date date1, Date date2)

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

Description

difference On Year

License

Open Source License

Declaration

public static int differenceOnYear(Date date1, Date date2) 

Method Source Code

//package com.java2s;

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

public class Main {

    public static int differenceOnYear(Date date1, Date date2) {
        if (date1 == null || date2 == null) {
            return 0;
        }/*from w  w w.  j  a v  a 2 s. co  m*/
        int year1 = getDateYear(date1);
        int year2 = getDateYear(date2);

        return Math.abs(year1 - year2);
    }

    public static int getDateYear(Date date) {
        if (date == null)
            return 0;

        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        return cal.get(Calendar.YEAR);
    }
}

Related

  1. DifferenceInMilliseconds(Date date1, Date date2)
  2. differenceInMonths(Date beginningDate, Date endingDate)
  3. DifferenceInSeconds(Date date1, Date date2)
  4. differenceMonth(Date date1, Date date2)
  5. differenceOnMonth(Date date1, Date date2)
  6. diffIntoMilliSecond(java.util.Date date, java.util.Date date1)
  7. diffMillis(Date d1, Date d2)
  8. diffMonth(Date before, Date after)
  9. diffMonth(Date start, Date end)