mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:37:59 +08:00
IdcardUtil增加convert18To15方法
This commit is contained in:
parent
ac3fc026e1
commit
c7bb17138e
@ -8,6 +8,8 @@
|
||||
### 🐣新特性
|
||||
* 【core 】 BooleanUtil的andOfWrap和orOfWrap()忽略null(issue#2599@Github)
|
||||
* 【jwt 】 优化JWT自动识别header中的算法,并可自定义header中key的顺序(issue#I5QRUO@Gitee)
|
||||
* 【core 】 IdcardUtil增加convert18To15方法(issue#I5QYCP@Gitee)
|
||||
|
||||
### 🐞Bug修复
|
||||
* 【core 】 修复ObjectUtil.defaultIfXXX中NPE问题(pr#2603@Github)
|
||||
* 【db 】 修复Hive2驱动无法识别问题(issue#2606@Github)
|
||||
|
@ -146,6 +146,19 @@ public class IdcardUtil {
|
||||
return idCard18.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 将18位身份证号码转换为15位
|
||||
*
|
||||
* @param idCard 18位身份编码
|
||||
* @return 15位身份编码
|
||||
*/
|
||||
public static String convert18To15(String idCard) {
|
||||
if (StrUtil.isNotBlank(idCard) && IdcardUtil.isValidCard18(idCard)) {
|
||||
return idCard.substring(0, 6) + idCard.substring(8, idCard.length() - 1);
|
||||
}
|
||||
return idCard;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否有效身份证号,忽略X的大小写<br>
|
||||
* 如果身份证号码中含有空格始终返回{@code false}
|
||||
|
@ -46,6 +46,12 @@ public class IdcardUtilTest {
|
||||
Assert.assertEquals("33010219200403064X", convert15To18Second);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convert18To15Test() {
|
||||
String idcard15 = IdcardUtil.convert18To15("150102198807303035");
|
||||
Assert.assertEquals(ID_15, idcard15);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAgeByIdCardTest() {
|
||||
DateTime date = DateUtil.parse("2017-04-10");
|
||||
|
Loading…
Reference in New Issue
Block a user