Commit 7727d7a4 authored by 李灿灿's avatar 李灿灿

周岁工具类调整

parent 7e4fe0db
...@@ -33,7 +33,6 @@ public class IdCardUtil { ...@@ -33,7 +33,6 @@ public class IdCardUtil {
/** /**
* 根据身份证号计算周岁 * 根据身份证号计算周岁
* 例如:当前时间是2022-08-22,那么2007-08-22算15周岁,2007-08-23才算16周岁
* *
* @author licancan * @author licancan
* @param idNO * @param idNO
...@@ -58,11 +57,12 @@ public class IdCardUtil { ...@@ -58,11 +57,12 @@ public class IdCardUtil {
int yearBirth = bir.get(Calendar.YEAR); int yearBirth = bir.get(Calendar.YEAR);
int monthBirth = bir.get(Calendar.MONTH); int monthBirth = bir.get(Calendar.MONTH);
int dayBirth = bir.get(Calendar.DAY_OF_MONTH); int dayBirth = bir.get(Calendar.DAY_OF_MONTH);
// 大概年龄是当前年减去出生年 int age;
int age = yearNow - yearBirth; // 如果当前月大于出生月,或者当前月等于出生月但是当前日大于出生日 直接减,否则再减1
// 如果出当前月大于出生月,或者当前月等于出生月但是当前日大于出生日,那么年龄age就加一岁 if ((monthBirth < monthNow) || (monthBirth == monthNow && dayBirth < dayNow)) {
if (monthNow > monthBirth || (monthNow == monthBirth && dayNow > dayBirth)) { age = yearNow - yearBirth;
age++; } else {
age = yearNow - yearBirth - 1;
} }
return age; return age;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment