Android 身份证出生日期与系统当前时间判断年龄

  

项目中刚遇到针对身份证号做出年龄判断对18岁以下理财用户的舍去方案,贴出来大家一起共享吧!!!


 
 
// 判断是否成年
    public static boolean isAdult(String str){
        //新版身份证十八位,老版身份证是十五位
       if (isEmpty(str)||(15!=str.length()&&18!=str.length())) {
            return false;
        }else {
            String birthday=str.substring(6, str.length()-4);
            Calendar calendar=Calendar.getInstance();
            calendar.set(Integer.parseInt(birthday.substring(0, 4))+18, Integer.parseInt(birthday.substring(4, 6))-1, Integer.parseInt(birthday.substring(6)),23,59);
            return 0<=System.currentTimeMillis()-calendar.getTimeInMillis();
        }
    }

猜你喜欢

转载自blog.csdn.net/qq_34619754/article/details/53515797