code: public static int getAge(String idCard) {
          int age;
          // 计算用户年龄
          int year = Integer.parseInt(idCard.substring(6, 10));
          int monthDay = Integer.parseInt(idCard.substring(10, 14));
          Calendar calendar = Calendar.getInstance();
          int nowYear = calendar.get(Calendar.YEAR);
          int nowMonthDay = calendar.get(Calendar.MONTH) * 100 + calendar.get(Calendar.DATE);
          if (nowMonthDay > monthDay) {
              age = nowYear - year;
          } else {
              age = nowYear - year - 1;
  
          }
          if (age < 0) {
              logger.warn("身份证年龄应该大于等于0，但是实际年龄为{}", age);
          }
          return age;
      }
docs: 获取用户年龄
  
  @param idCard 用户身份证号
  @return 用户年龄