年龄修改
This commit is contained in:
parent
10d83ecac4
commit
49dc4d3130
|
|
@ -745,9 +745,9 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||||
|
|
||||||
// 若还未到今年生日,年龄减1
|
// 若还未到今年生日,年龄减1
|
||||||
int age = period.getYears();
|
int age = period.getYears();
|
||||||
if (now.isBefore(birthDate.withYear(now.getYear()))) {
|
/* if (now.isBefore(birthDate.withYear(now.getYear()))) {
|
||||||
age--;
|
age--;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
return Math.max(age, 0); // 防止负数(如未来日期)
|
return Math.max(age, 0); // 防止负数(如未来日期)
|
||||||
} catch (DateTimeParseException | IndexOutOfBoundsException e) {
|
} catch (DateTimeParseException | IndexOutOfBoundsException e) {
|
||||||
|
|
@ -755,6 +755,11 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
String id = "513127199410222247";
|
||||||
|
System.out.println("实际年龄"+calculateAge(id));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 身份证脱敏处理
|
* 身份证脱敏处理
|
||||||
* 保留前6位和后4位,中间用*替代
|
* 保留前6位和后4位,中间用*替代
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue