From 8228d16a53c3f441eb3a26b00f17dd6fbaf7ae1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E9=9B=B7?= <284428564@QQ.com> Date: Thu, 17 Oct 2024 11:33:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B9=B4=E9=BE=84=E6=8C=89=E7=85=A7=E7=94=9F?= =?UTF-8?q?=E6=97=A5=E8=AE=A1=E7=AE=97=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TelpoPush.Ability.Worker/Common/TimeHelper.cs | 22 +++++++++++++++++++ .../Service/Biz/PsychHealthData.cs | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/TelpoPush.Ability.Worker/Common/TimeHelper.cs b/TelpoPush.Ability.Worker/Common/TimeHelper.cs index 577982f..ab9bbd0 100644 --- a/TelpoPush.Ability.Worker/Common/TimeHelper.cs +++ b/TelpoPush.Ability.Worker/Common/TimeHelper.cs @@ -60,5 +60,27 @@ namespace TelpoPush.Ability.Worker.Common return dt.ToString("yyyy-MM-dd"); } + /// + /// 计算年龄 + /// + /// 出生日期(生日) + /// 年:true(年);false(月,天) + /// + public static int GetAge(DateTime birthday,bool isYear=false) { + + DateTime today = DateTime.Today; + if (today < birthday) + return 0; + + // 计算年龄 + int age = today.Year - birthday.Year; + if (!isYear) + { + // 如果今天日期还没到生日日期,则年龄减一 + if (today.Month < birthday.Month || (today.Month == birthday.Month && today.Day < birthday.Day)) + age--; + } + return age; + } } } diff --git a/TelpoPush.Ability.Worker/Service/Biz/PsychHealthData.cs b/TelpoPush.Ability.Worker/Service/Biz/PsychHealthData.cs index bd20265..15a6c3e 100644 --- a/TelpoPush.Ability.Worker/Service/Biz/PsychHealthData.cs +++ b/TelpoPush.Ability.Worker/Service/Biz/PsychHealthData.cs @@ -122,7 +122,7 @@ namespace TelpoPush.Ability.Worker.Service.Biz //65~74 1 1 //>= 75 2 2 bool isAge = false; - int age = DateTime.Now.Year - person.birth.Value.Year; + int age = TimeHelper.GetAge(person.birth.Value);// DateTime.Now.Year - person.birth.Value.Year; if (age >= 65 && age <= 74) { hisDate.birth = [1, 1];