public static int getAgeByBirthday(Date birthday) { Calendar cal = Calendar.getInstance(); if (cal.before(birthday)) { throw new IllegalArgumentException( "你还没出生呢"); } int yearNow = cal.get(Calendar.YEAR); cal.setTime(birthday); int yearBirth = cal.get(Calendar.YEAR); int age = yearNow - yearBirth; return age; }