Java Date to Year getYearBetweenTwoDate(Date fdate, Date tdate)

Here you can find the source of getYearBetweenTwoDate(Date fdate, Date tdate)

Description

Return offset years between specified begin date and end date

License

Open Source License

Parameter

Parameter Description
fdate begin date
tdate end date

Return

offset number

Declaration

public static int getYearBetweenTwoDate(Date fdate, Date tdate) 

Method Source Code


//package com.java2s;
/*//from   w ww .jav a 2s .c o m
 * File: $RCSfile$
 *
 * Copyright (c) 2005 Wincor Nixdorf International GmbH,
 * Heinz-Nixdorf-Ring 1, 33106 Paderborn, Germany
 * All Rights Reserved.
 *
 * This software is the confidential and proprietary information
 * of Wincor Nixdorf ("Confidential Information"). You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered
 * into with Wincor Nixdorf.
 */

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

public class Main {
    /**
     * Return offset years between specified begin date and end date
     *
     * @param fdate begin date
     * @param tdate end date
     * @return offset number
     */
    public static int getYearBetweenTwoDate(Date fdate, Date tdate) {
        Calendar f = Calendar.getInstance();
        f.setTime(fdate);
        Calendar t = Calendar.getInstance();
        t.setTime(tdate);

        return t.get(Calendar.YEAR) - f.get(Calendar.YEAR);
    }
}

Related

  1. getYear(java.util.Date today)
  2. getYear(String sdate)
  3. getYear(String strDate)
  4. getYearAsInt(Date aDate)
  5. getYearBegin(final Date date)
  6. getYearFromDate(Date date)
  7. getYearFromDate(Date date)
  8. getYearMonth(Date date)
  9. getYearMonthDay(Date date)