根据生日计算年龄

/**
	 * 计算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);
	}

  

posted @ 2022-03-04 14:35  红尘沙漏  阅读(10)  评论(0编辑  收藏  举报