zoukankan      html  css  js  c++  java
  • java身份证计算年龄

    技术交流群: 233513714

        /**
         * 根据身份证计算年龄
         *
         * @param idcard
         * @return
         */
        public static Integer idCardToAge(String idcard) {
            Integer selectYear = Integer.valueOf(idcard.substring(6, 10));         //出生的年份
            Integer selectMonth = Integer.valueOf(idcard.substring(10, 12));       //出生的月份
            Integer selectDay = Integer.valueOf(idcard.substring(12, 14));         //出生的日期
            Calendar cal = Calendar.getInstance();
            Integer yearMinus = cal.get(Calendar.YEAR) - selectYear;
            Integer monthMinus = cal.get(Calendar.MONTH) + 1 - selectMonth;
            Integer dayMinus = cal.get(Calendar.DATE) - selectDay;
            Integer age = yearMinus;
            if (yearMinus < 0) {
                age = 0;
            } else if (yearMinus == 0) {
                age = 0;
            } else if (yearMinus > 0) {
                if (monthMinus == 0) {
                    if (dayMinus < 0) {
                        age = age - 1;
                    }
                } else if (monthMinus > 0) {
                    age = age + 1;
                }
            }
            return age;
        }





  • 相关阅读:
    scjp考试准备
    scjp考试准备
    scjp考试准备
    scjp考试准备
    maven学习手记
    maven学习手记
    ExtJS MVC 学习手记3
    调整maven配置文件
    ExtJS MVC学习手记 2
    ExtJS MVC学习手记 1
  • 原文地址:https://www.cnblogs.com/cnndevelop/p/7080849.html
Copyright © 2011-2022 走看看