| 
						
						
						
					 | 
				
				 | 
				
					@ -1,9 +1,11 @@ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					package com.epmet.commons.tools.validator; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import org.apache.commons.lang3.StringUtils; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import org.slf4j.Logger; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import org.slf4j.LoggerFactory; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import java.text.SimpleDateFormat; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import java.time.LocalDate; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import java.util.Calendar; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import java.util.GregorianCalendar; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					import java.util.Hashtable; | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -199,5 +201,47 @@ public class IdCardNoValidatorUtils { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        return gender; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    /** | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     * 根据身份证号获取年龄 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     * | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     * @param IDCard 完整身份证号码 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     * @return java.lang.Integer | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     * @author work@yujt.net.cn | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     * @date 2019/9/20 14:26 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     */ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    public static Integer getAge(String IDCard) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        int age; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        LocalDate now = LocalDate.now(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        int nowYear = now.getYear(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        int nowMonth = now.getMonthValue(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        int cardYear = 0; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        int cardMonth = 0; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        if (StringUtils.isNotBlank(IDCard) && checkIsIdCardNo(IDCard)) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            if (IDCard.length() == 15) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                // 身份证上的年份(15位身份证为1980年前的)
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                String uyear = "19" + IDCard.substring(6, 8); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                cardYear = Integer.parseInt(uyear); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                // 身份证上的月份
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                String uyue = IDCard.substring(8, 10); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                cardMonth = Integer.parseInt(uyue); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            } else if (IDCard.length() == 18) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                // 身份证上的年份
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                String year = IDCard.substring(6).substring(0, 4); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                cardYear = Integer.parseInt(year); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                // 身份证上的月份
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                String yue = IDCard.substring(10).substring(0, 2); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                cardMonth = Integer.parseInt(yue); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        // 当前月份大于用户出身的月份表示已过生日
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        if (cardMonth <= nowMonth) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            age = nowYear - cardYear + 1; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            // 当前用户还没过生
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } else { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            age = nowYear - cardYear; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        return age; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
					 | 
				
				 | 
				
					
  |