import java.text.ParseException;
import java.util.Date;
import com.blankj.utilcode.util.LogUtils;
/**
* 身份证工具
*/
public class ComposeUtil {
/**
* 根据身份证号获取生日
*
* @param composeStr
* @return
*/
public static Date getBirthdayByCompose(String composeStr) {
String year = composeStr.substring(6, 10);
String month = composeStr.substring(10, 12);
String day = composeStr.substring(12, 14);
LogUtils.e("ComposeUtil", year + "-" + month + "-" + day);
try {
return DateUtil.toDate(year + "-" + month + "-" + day);
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
/**
* Description: 检查身份证号码是否符合规则
*
* @param idCode
* String 身份证号码
* @return boolean 身份证号码正确,则返回true,否则返回false
*/
public static boolean isComposeNumber(String idCode) {
int ai[] = { 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1 };
boolean flag = false;
if (idCode != null)
switch (idCode.length()) {
default:
break;
case 15: // '\017'
flag = true;
break;
case 18: // '\022'
int i = 0;
for (int k = 0; k < 18; k++) {
char c = idCode.charAt(k);
int j;
if (c == 'X' || c == 'x')
j = 10;
else if (c <= '9' || c >= '0')
j = c - 48;
else
return flag;
i += j * ai[k];
}
if (i % 11 == 1)
flag = true;
break;
}
return flag;
}
}
04-12
12-09
1万+
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)