Here you can find the source of getYearNumber(Date date)
Parameter | Description |
---|---|
date | a parameter |
public static Integer getYearNumber(Date date)
//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; } }