From d7910b2f4789fe6c76cb104e36edb8ccbb67d25e Mon Sep 17 00:00:00 2001
From: wuxw <928255095@qq.com>
Date: 星期五, 23 四月 2021 11:08:39 +0800
Subject: [PATCH] 优化地爱吗
---
java110-utils/src/main/java/com/java110/utils/util/CommonUtil.java | 31 ++++++++++++++++++++++++++++++-
1 files changed, 30 insertions(+), 1 deletions(-)
diff --git a/java110-utils/src/main/java/com/java110/utils/util/CommonUtil.java b/java110-utils/src/main/java/com/java110/utils/util/CommonUtil.java
old mode 100644
new mode 100755
index f4f6c5b..b425010
--- a/java110-utils/src/main/java/com/java110/utils/util/CommonUtil.java
+++ b/java110-utils/src/main/java/com/java110/utils/util/CommonUtil.java
@@ -4,6 +4,9 @@
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.util.StringUtils;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
import java.util.Random;
/**
@@ -56,7 +59,7 @@
String result = "";
for (int i = 0; i < 6; i++) {
- result += random.nextInt(10);
+ result += (random.nextInt(9) + 1);;
}
return result;
@@ -95,4 +98,30 @@
}
return false;
}
+
+
+ /**
+ * 鏍规嵁韬唤璇佸彿鑾峰彇骞撮緞
+ * @param certId
+ * @return
+ */
+ public static String getAgeByCertId(String certId) {
+ String birthday = "";
+ if (certId.length() == 18) {
+ birthday = certId.substring(6, 10) + "/"
+ + certId.substring(10, 12) + "/"
+ + certId.substring(12, 14);
+ }
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
+ Date now = new Date();
+ Date birth = new Date();
+ try {
+ birth = sdf.parse(birthday);
+ } catch (ParseException e) {
+ }
+ long intervalMilli = now.getTime() - birth.getTime();
+ int age = (int) (intervalMilli/(24 * 60 * 60 * 1000))/365;
+ System.out.println(age);
+ return age +"";
+ }
}
--
Gitblit v1.8.0