zoukankan      html  css  js  c++  java
  • 身份证号判断周岁

    public Integer checkExpertAge(String idCard) {
        //  1.  获取身份证中的出生年、月、日
        Integer personYear = Integer.parseInt(idCard.substring(6, 10));
        Integer personMonth = Integer.parseInt(idCard.substring(10, 12));
        Integer personDay = Integer.parseInt(idCard.substring(12, 14));
        //  2.  获取当前时间的年、月、日
        Calendar cal = Calendar.getInstance();
        Integer yearNow = cal.get(Calendar.YEAR);
        Integer monthNow = cal.get(Calendar.MONTH) + 1;
        Integer dayNow = cal.get(Calendar.DATE);
        //  3.  用当前年月日减去生日年月日
        Integer yearMinus = yearNow - personYear;
        Integer monthMinus = monthNow - personMonth;
        Integer dayMinus = dayNow - personDay;
        //  4.  周岁判断
        Integer age = yearMinus;
        if (yearMinus == 0) {
            //  出生年份为当前年份
            age = 0;
        } else {
            //  出生年份大于当前年份
            if (monthMinus < 0) {
                //  出生月份小于当前月份时,还没满周岁
                age = age - 1;
            }
            if (monthMinus == 0) {
                //  当前月份为出生月份时,判断日期
                if (dayMinus < 0) {
                    //  出生日期小于当前月份时,没满周岁
                    age = age - 1;
                }
            }
        }return age;
    }
  • 相关阅读:
    《算法竞赛入门经典》(刘汝佳)——排序与检索(基础)
    Python中的GIL
    MongoDB 安装
    python3 报错集合
    socket 实例化方法
    socket入门
    Day_6作业_模拟人生
    高阶函数举例
    面向对象_python
    xml
  • 原文地址:https://www.cnblogs.com/shiblog/p/11613156.html
Copyright © 2011-2022 走看看