Java Date to Year getYearNumber(Date date)

Here you can find the source of getYearNumber(Date date)

Description

Retourne le nombre d'annee par rapport a la date du jour.

License

Open Source License

Parameter

Parameter Description
date a parameter

Declaration

public static Integer getYearNumber(Date date) 

Method Source Code

//package com.java2s;
/*****************************************************************************
 * Copyright (c) 2009//from ww  w  .j  ava2 s.  c om
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Angelo Zerr <angelo.zerr@gmail.com>
 *     Jawher Moussa <jawher.moussa@gmail.com>
 *     Nicolas Inchauspe <nicolas.inchauspe@gmail.com>
 *     Pascal Leclercq <pascal.leclercq@gmail.com>
 *******************************************************************************/

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

public class Main {
    /**
     * Retourne le nombre d'annee par rapport a la date du jour.
     * @param date
     * @return
     */
    public static Integer getYearNumber(Date date) {
        Integer yearNumber = null;
        if (date != null) {
            // Create a calendar object with the date of birth
            Calendar dateYear = new GregorianCalendar();
            dateYear.setTime(date);

            // Create a calendar object with today's date
            Calendar today = Calendar.getInstance();
            int year = today.get(Calendar.YEAR) - dateYear.get(Calendar.YEAR);
            yearNumber = year;
        }
        return yearNumber;
    }
}

Related

  1. getYearMonth(Date date)
  2. getYearMonthDay(Date date)
  3. getYearMonthDay(Date date)
  4. getYearMonthInt(Date date)
  5. getYearMonthOfLastMon(Date date)
  6. getYearOfDate(Date date)
  7. getYearOfThisYear(Date currentdate)
  8. getYearOnlyDate(String year)
  9. getYears(java.util.Date date0, java.util.Date date1)