标签:
private static int getAge(String birthDate) throws Exception { SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); Calendar calBirth = Calendar.getInstance(); calBirth.setTime(sdf.parse(birthDate)); Calendar cal = Calendar.getInstance(); int yearDiff = cal.get(Calendar.YEAR) - calBirth.get(Calendar.YEAR); calBirth.add(Calendar.YEAR, yearDiff); if (cal.getTimeInMillis() - calBirth.getTimeInMillis() < 0) { return yearDiff - 1; } return yearDiff; }
标签:
原文地址:http://www.cnblogs.com/anni6/p/4929430.html