Java Day Between getYearsDifference(Date startTime, Date endTime)

Here you can find the source of getYearsDifference(Date startTime, Date endTime)

Description

get Years Difference

License

Open Source License

Declaration

public static int getYearsDifference(Date startTime, Date endTime) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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

public class Main {

    public static int getYearsDifference(Date startTime, Date endTime) {
        Calendar calendarStart = Calendar.getInstance();
        Calendar calendarEnd = Calendar.getInstance();
        calendarStart.setTime(startTime);
        calendarEnd.setTime(endTime);/*from  w  ww.  j  a va2 s  . c  o m*/
        return (calendarEnd.get(Calendar.YEAR) - calendarStart.get(Calendar.YEAR))
                + (calendarStart.get(Calendar.MONTH) == 0 ? 0 : 1);
    }

    public static int getYearsDifference(Date startTime) {
        return getYearsDifference(startTime, new Date());
    }
}

Related

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