Java Day Between getYearDiff(Date date1, Date date2)

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

Description

get Year Diff

License

Apache License

Declaration

public static int getYearDiff(Date date1, Date date2) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

public class Main {

    public static int getYearDiff(Date date1, Date date2) {
        if (date1 == null || date2 == null) {
            return 0;
        }//from w w  w . ja  v  a 2 s  .  c o  m

        Calendar calendar1 = Calendar.getInstance();
        calendar1.setTime(date1);
        int year1 = calendar1.get(Calendar.YEAR);

        Calendar calendar2 = Calendar.getInstance();
        calendar2.setTime(date2);
        int year2 = calendar2.get(Calendar.YEAR);

        return Math.abs(year1 - year2);
    }
}

Related

  1. getTimeDifference(Date d1, Date d2)
  2. getTimeDifference(Date date1, Date date2)
  3. getTimeDifference(Date otherDate)
  4. getTodayDiff(String diffDate)
  5. getWorkingDaysBetween(Date fromDate, Date toDate)
  6. getYearsDifference(Date startTime, Date endTime)
  7. hourDiff(Date firstDate, Date lastDate)
  8. internalTrimOrAlterDate(Date date, boolean trim, int dayDiff)
  9. monthDiff(Date beginDate, Date endDate)