Java tutorial
//package com.java2s; /** * @copyright Urucas * @license Copyright (C) 2013. All rights reserved * @version Release: 1.0.0 * @link http://urucas.com * @developers Bruno Alassia, Pamela Prosperi */ import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { public static String getAge(String fec_nac) { DateFormat df = new SimpleDateFormat("yyyy-mm-dd"); Calendar dob = Calendar.getInstance(); Date d = null; try { d = df.parse(fec_nac); } catch (Exception e) { } Calendar today = Calendar.getInstance(); dob.setTime(d); int age = today.get(Calendar.YEAR) - dob.get(Calendar.YEAR); if (today.get(Calendar.DAY_OF_YEAR) < dob.get(Calendar.DAY_OF_YEAR)) { age--; } return String.valueOf(age); } }