From e4be5ba9eea9fe8408f3a7048a315b3767b33f49 Mon Sep 17 00:00:00 2001
From: MrShi <1878285526@qq.com>
Date: 星期五, 23 二月 2024 09:54:38 +0800
Subject: [PATCH] mrshi

---
 company/src/utils/util.js |   57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 57 insertions(+), 0 deletions(-)

diff --git a/company/src/utils/util.js b/company/src/utils/util.js
index bc975bc..779f5a3 100644
--- a/company/src/utils/util.js
+++ b/company/src/utils/util.js
@@ -18,3 +18,60 @@
   }
   return data
 }
+
+// 鏍规嵁韬唤璇佽幏鍙栧勾榫�
+export function GetAge (identityCard) {
+  let len = (identityCard + "").length;
+  let strBirthday = "";
+  if (len === 18) {
+    //澶勭悊18浣嶇殑韬唤璇佸彿鐮佷粠鍙风爜涓緱鍒扮敓鏃ュ拰鎬у埆浠g爜
+    strBirthday =
+        identityCard.substr(6, 4) +
+        "/" +
+        identityCard.substr(10, 2) +
+        "/" +
+        identityCard.substr(12, 2);
+  }
+  if (len === 15) {
+    let birthdayValue = "";
+    birthdayValue = identityCard.charAt(6) + identityCard.charAt(7);
+    if (parseInt(birthdayValue) < 10) {
+      strBirthday =
+          "20" +
+          identityCard.substr(6, 2) +
+          "/" +
+          identityCard.substr(8, 2) +
+          "/" +
+          identityCard.substr(10, 2);
+    } else {
+      strBirthday =
+          "19" +
+          identityCard.substr(6, 2) +
+          "/" +
+          identityCard.substr(8, 2) +
+          "/" +
+          identityCard.substr(10, 2);
+    }
+  }
+  let birthDate = new Date(strBirthday);
+  let nowDateTime = new Date();
+  let age = nowDateTime.getFullYear() - birthDate.getFullYear();
+  //鍐嶈�冭檻鏈堛�佸ぉ鐨勫洜绱�;.getMonth()鑾峰彇鐨勬槸浠�0寮�濮嬬殑锛岃繖閲岃繘琛屾瘮杈冿紝涓嶉渶瑕佸姞1
+  if (
+      nowDateTime.getMonth() < birthDate.getMonth() ||
+      (nowDateTime.getMonth() == birthDate.getMonth() &&
+          nowDateTime.getDate() < birthDate.getDate())
+  ) {
+    age--;
+  }
+  return age;
+}
+
+// 鑾峰彇褰撳墠鏃ユ湡
+export function getDate() {
+  let currentDate = new Date();
+  let year = currentDate.getFullYear(); // 鑾峰彇褰撳墠骞翠唤
+  let month = currentDate.getMonth() + 1; // 鑾峰彇褰撳墠鏈堜唤锛屾敞鎰忔湀浠戒粠0寮�濮嬶紝鎵�浠ヨ鍔�1
+  let day = currentDate.getDate(); // 鑾峰彇褰撳墠鏃ユ湡
+  return `${year}-${month}-${day}`
+}

--
Gitblit v1.9.3