根据生日计算年龄
/** * 计算startDate和endDate相差多少年 * @param startDate * @param endDate * @return */ public static int yearDateDiff(String startDate, Date endDate) { Calendar calBegin = Calendar.getInstance(); // 获取日历实例 Calendar calEnd = Calendar.getInstance(); calBegin.setTime(stringTodate(startDate, "yyyyMMddhhmmss")); // 字符串按照指定格式转化为日期 calEnd.setTime(endDate); int calEndYear = calEnd.get(Calendar.YEAR); int calBeginYear = calBegin.get(Calendar.YEAR); return calEnd.get(Calendar.YEAR) - calBegin.get(Calendar.YEAR); }