| | |
| | | package com.panzhihua.common.utlis; |
| | | |
| | | import cn.hutool.core.util.IdcardUtil; |
| | | import com.panzhihua.common.constants.Constants; |
| | | |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | |
| | | return age - 1; |
| | | } |
| | | |
| | | /** |
| | | * 根据身份证号判断年龄段 |
| | | * @param idCard 身份证号 |
| | | * @return 年龄段(1.80-89周岁 2.90-99周岁 3.100周岁(含)以上) |
| | | */ |
| | | public static int getAgeCategory(String idCard){ |
| | | int nub = -1; |
| | | int age = 0; |
| | | try { |
| | | age = IdcardUtil.getAgeByIdCard(idCard); |
| | | }catch (Exception e){ |
| | | return -1; |
| | | } |
| | | if (age >= Constants.EIGHTY && age < Constants.NINETY) { |
| | | nub = 1; |
| | | }else if (age >= Constants.NINETY && age < Constants.ONE_HUNDRED){ |
| | | nub = 2; |
| | | }else if (age >= Constants.ONE_HUNDRED){ |
| | | nub = 3; |
| | | } |
| | | return nub; |
| | | } |
| | | |
| | | public static int getAgeFromBirthTimes(long birthTimeLong) { |
| | | Date date = new Date(birthTimeLong * 1000l); |
| | | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); |