Java Day End getYearsBetweenDate(Date begin, Date end)

Here you can find the source of getYearsBetweenDate(Date begin, Date end)

Description

get Years Between Date

License

Apache License

Declaration

public static int getYearsBetweenDate(Date begin, Date end) 

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 getYearsBetweenDate(Date begin, Date end) {
        int bYear = getDateField(begin, Calendar.YEAR);
        int eYear = getDateField(end, Calendar.YEAR);
        return eYear - bYear;
    }//from   w w w  .  j av a 2 s.  c  o m

    private static int getDateField(Date date, int field) {
        Calendar c = getCalendar();
        c.setTime(date);
        return c.get(field);
    }

    private static Calendar getCalendar() {
        return Calendar.getInstance();
    }

    public static int get(int field, Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return c.get(field);
    }
}

Related

  1. getTotalMonths(final Date startDateToCheck, final Date endDateToCheck)
  2. getTrendTime(Date date)
  3. getWorkingDays(Calendar start, Calendar end, final Long[] holidays)
  4. getWorkingDaysBetweenTwoDates(Date startDate, Date endDate)
  5. getYearsBetween(Date startDate, Date endDate)
  6. isBetweenDate(Date date, Date startDate, Date endDate)
  7. isBetWeenDates(Date in, Date from, Date to)
  8. isCalenderDaySame(GregorianCalendar aInCal1, GregorianCalendar aInCal2)
  9. isEndOfMonth(Date d)