From a9f950c0d11a687a7a940443b8c765f6d87ae4f1 Mon Sep 17 00:00:00 2001
From: jyy <935090232@qq.com>
Date: Tue, 20 Apr 2021 00:26:22 +0800
Subject: [PATCH] 合并新的修改
---
zq-erp/src/main/java/com/matrix/core/tools/DateUtil.java | 37 ++++++++++++++++++++++++++++++++++++-
1 files changed, 36 insertions(+), 1 deletions(-)
diff --git a/zq-erp/src/main/java/com/matrix/core/tools/DateUtil.java b/zq-erp/src/main/java/com/matrix/core/tools/DateUtil.java
index 4fdaef7..07a0984 100644
--- a/zq-erp/src/main/java/com/matrix/core/tools/DateUtil.java
+++ b/zq-erp/src/main/java/com/matrix/core/tools/DateUtil.java
@@ -720,10 +720,45 @@
targetDate = calendar.getTime();
break;
default:
- targetDate = new Date();
+ targetDate = stringToDate("9999-12-31", DATE_FORMAT_DD);
}
return targetDate;
}
+
+ public static String getAgeForBirthDay(Date birthDay) {
+ Calendar cal = Calendar.getInstance();
+ if (birthDay == null) {
+ return "-";
+ }
+ // 出生日期晚于当前时间,无法计算
+ if (cal.before(birthDay)) {
+ return "-";
+ }
+ // 当前年份
+ int yearNow = cal.get(Calendar.YEAR);
+ // 当前月份
+ int monthNow = cal.get(Calendar.MONTH);
+ // 当前日期
+ int dayOfMonthNow = cal.get(Calendar.DAY_OF_MONTH);
+ cal.setTime(birthDay);
+ int yearBirth = cal.get(Calendar.YEAR);
+ int monthBirth = cal.get(Calendar.MONTH);
+ int dayOfMonthBirth = cal.get(Calendar.DAY_OF_MONTH);
+ // 计算整岁数
+ Integer age = yearNow - yearBirth;
+ if (monthNow <= monthBirth) {
+ if (monthNow == monthBirth) {
+ if (dayOfMonthNow < dayOfMonthBirth) {
+ // 当前日期在生日之前,年龄减一
+ age--;
+ }
+ } else {
+ age--;
+ }
+ }
+
+ return age.toString();
+ }
}
--
Gitblit v1.9.1