Here you can find the source of age(int year, int month, int date)
Parameter | Description |
---|---|
year | a parameter |
month | a parameter |
date | a parameter |
public static int age(int year, int month, int date)
//package com.java2s; import java.util.Calendar; import java.util.GregorianCalendar; public class Main { /**// w w w . j av a 2 s . com * This method returns the age on the basis of parameter passed to the method. * * @param year * @param month * @param date * @return age */ public static int age(int year, int month, int date) { Calendar cal = new GregorianCalendar(year, month, date); Calendar now = new GregorianCalendar(); int age = now.get(Calendar.YEAR) - cal.get(Calendar.YEAR); if ((cal.get(Calendar.MONTH) > now.get(Calendar.MONTH)) || (cal.get(Calendar.MONTH) == now.get(Calendar.MONTH) && cal.get(Calendar.DAY_OF_MONTH) > now.get(Calendar.DAY_OF_MONTH))) { age--; } return age; } }