Date today = new Date();
Integer currentYear = new Integer(DateTimeFormat.getFormat("yyyy").format(today));
Integer currentMonth = new Integer(DateTimeFormat.getFormat("M").format(today));
Integer currentDay = new Integer(DateTimeFormat.getFormat("d").format(today));
Age calculating function:
public static int calculateAge(Date dob)
{
Date today = new Date();
Integer currentYear = new Integer(DateTimeFormat.getFormat("yyyy").format(today));
Integer currentMonth = new Integer(DateTimeFormat.getFormat("M").format(today));
Integer currentDay = new Integer(DateTimeFormat.getFormat("d").format(today));
Integer dobYear = new Integer(DateTimeFormat.getFormat("yyyy").format(dob));
Integer dobMonth = new Integer(DateTimeFormat.getFormat("M").format(dob));
Integer dobDay = new Integer(DateTimeFormat.getFormat("d").format(dob));
int age = currentYear - dobYear;
if((dobMonth > currentMonth) || (currentMonth == dobMonth && dobDay > currentDay))
age--;
return age;
}