Java Date to Year getYears(java.util.Date date0, java.util.Date date1)

Here you can find the source of getYears(java.util.Date date0, java.util.Date date1)

Description

get Years

License

Open Source License

Declaration

public static int getYears(java.util.Date date0, java.util.Date date1) 

Method Source Code

//package com.java2s;

import java.util.Calendar;

public class Main {
    public static int getYears(java.util.Date date0, java.util.Date date1) {

        Calendar calendar0 = Calendar.getInstance();
        calendar0.setTime(date0);/* www .  j  av a 2 s  . c  om*/

        Calendar calendar1 = Calendar.getInstance();
        calendar1.setTime(date1);

        int year0 = calendar0.get(Calendar.YEAR);
        int year1 = calendar1.get(Calendar.YEAR);

        int years = year1 - year0;

        return years;
    }
}

Related

  1. getYearMonthOfLastMon(Date date)
  2. getYearNumber(Date date)
  3. getYearOfDate(Date date)
  4. getYearOfThisYear(Date currentdate)
  5. getYearOnlyDate(String year)
  6. getYearStart(Date date)
  7. getYearString(Date date)