import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.HashMap;

import java.util.Map;

public class CardUtil {

/**

* 根据身份证的号码算出当前身份证持有者的性别和年龄 18位身份证

*

* @return

* @throws Exception

*/

public static Map<String, Object> getCarInfo(String CardCode)

throws Exception {

Map<String, Object> map = new HashMap<String, Object>();

String year = CardCode.substring(6).substring(0, 4);// 得到年份

String yue = CardCode.substring(10).substring(0, 2);// 得到月份

// String day=CardCode.substring(12).substring(0,2);//得到日

Integer sex;

if (Integer.parseInt(CardCode.substring(16).substring(0, 1)) % 2 == 0) {// 判断性别

sex =1; //"女";

} else {

sex =0; //"男";

}

Date date = new Date();// 得到当前的系统时间

SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");

String fyear = format.format(date).substring(0, 4);// 当前年份

String fyue = format.format(date).substring(5, 7);// 月份

// String fday=format.format(date).substring(8,10);

int age = 0;

if (Integer.parseInt(yue) <= Integer.parseInt(fyue)) { // 当前月份大于用户出身的月份表示已过生

age = Integer.parseInt(fyear) - Integer.parseInt(year) + 1;

} else {// 当前用户还没过生

age = Integer.parseInt(fyear) - Integer.parseInt(year);

}

map.put("sex", sex);

map.put("age", age);

return map;

}

/**

* 15位身份证的验证

*

* @param

* @throws Exception

*/

public static Map<String, Object> getCarInfo15W(String card)throws Exception {

Map<String, Object> map = new HashMap<String, Object>();

String uyear = "19" + card.substring(6, 8);// 年份

String uyue = card.substring(8, 10);// 月份

// String uday=card.substring(10, 12);//日

String usex = card.substring(14, 15);// 用户的性别

String sex;

if (Integer.parseInt(usex) % 2 == 0) {

sex = "女";

} else {

sex = "男";

}

Date date = new Date();// 得到当前的系统时间

SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");

String fyear = format.format(date).substring(0, 4);// 当前年份

String fyue = format.format(date).substring(5, 7);// 月份

// String fday=format.format(date).substring(8,10);

int age = 0;

if (Integer.parseInt(uyue) <= Integer.parseInt(fyue)) { // 当前月份大于用户出身的月份表示已过生

age = Integer.parseInt(fyear) - Integer.parseInt(uyear) + 1;

} else {// 当前用户还没过生

age = Integer.parseInt(fyear) - Integer.parseInt(uyear);

}

map.put("sex", sex);

map.put("age", age);

return map;

}

}

CardUtil算出当前身份证持有者的性别和年龄的更多相关文章

  1. js脚本根据身份证号获取性别、年龄、家庭地址、生日

    做项目测试时需要根据身份证号获取其信息,也不想调接口,就自己在本地通过收集资料整合了一个

  2. js 根据身份证号获取性别,年龄,等

    $(function(){        $("#corpOwnerIdno").blur(function(){          //获取输入身份证号码             ...

  3. sqlalchemy 模型中添加根据身份证号计算性别和年龄

    class Users(Base, BaseMixin): username = Column(String(24)) id_Num = Column(String(18) ) # 身份证号码 @pr ...

  4. java根据身份证号和获取用户年龄和性别的工具类

    import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util ...

  5. PHP通过身份证号码获取性别、出生日期、年龄等信息

    $sex = substr($idcard, (strlen($idcard)==18 ? -2 : -1), 1) % 2 ? '1' : '2'; //18位身份证取性别,倒数第二位奇数是男,偶数 ...

  6. Excel通过身份证获取出生年月,性别,年龄,生肖,星座,省份等信息总结归纳

    Excel通过身份证获取出生年月,性别,年龄,生肖,星座,省份等信息总结归纳 早期的身份证号码为15位数字,现在使用的身份证号码为18位数字,它们的含义如下:(1)15位:1-6位为地区代码,7-8位 ...

  7. java 根据身份证号码获取出生日期、性别、年龄

      1.情景展示 如何根据身份证号,计算出出生日期.性别.年龄? 2.解决方案 从网上找的别人的,因为并没有实际用到,所以并未对其优化! /** * 通过身份证号码获取出生日期.性别.年龄 * @pa ...

  8. iOS之由身份证号返回性别

    该博文出自:http://www.cnblogs.com/yang-guang-girl/p/5683454.html - (void)viewDidLoad { [super viewDidLoad ...

  9. 【代码笔记】iOS-由身份证号码返回性别

    一,代码. - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. ...

随机推荐

  1. Bean property ‘mapperHelper’ is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

    spring boot 报错: Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property ...

  2. 201671030122 杨凡亿 实验十四 团队项目评审&课程学习总结

    项目 内容 课程名称 2016级计算机科学与工程学院软件工程(西北师范大学) 作业要求 实验十四 团队项目评审&课程学习总结 课程学习目标 (1)掌握软件项目评审会流程(2)反思总结课程学习内 ...

  3. Spring动态切换多数据源事务开启后,动态数据源切换失效解决方案

    关于某操作中开启事务后,动态切换数据源机制失效的问题,暂时想到一个取巧的方法,在Spring声明式事务配置中,可对不改变数据库数据的方法采用不支持事务的配置,如下: 对单纯查询数据的操作设置为不支持事 ...

  4. 前端jsp fetch跨域调用 is not allowed by Access-Control-Allow-Origin.

    之前我在用json跨域调用时,遇到如图问题,后来查查是官方json不支持跨域调用,后来改用非官方的jsonp跨域调用后台方法,出现如下问题 Origin http://127.0.0.1:8080 i ...

  5. Java中的Import语句如何理解?

    作用: 编译时:它只是进行语法检查和格式转换:与头文件作用相同. 运行时:依赖类加载. http://bbs.csdn.net/topics/390397328 前面说的java的编译,这里纠正一下, ...

  6. [React] Handle React Suspense Errors with an Error Boundary

    Error Boundaries are the way you handle errors with React, and Suspense embraces this completely. Le ...

  7. Wbbpack --3配置

    Wbbpack --3配置 什么是webpack webpack 是一个现代 JavaScript 应用程序的静态模块打包(modulebundler)当 webpack 处理应用程序时,它会递归地构 ...

  8. [RN] React Native 打包时 减少 Apk 的大小

    React Native 打包时 减少 Apk 的大小 主要有两个方法: 在打包前设置 android\app\build.gradle 文件中 1) def enableProguardInRele ...

  9. A1130 | 中缀表达式、查找根节点

    代码: #include <stdio.h> #include <memory.h> #include <math.h> #include <string&g ...

  10. CF732D Exams 题解

    CF732D Exams 题目描述 Vasiliy has an exam period which will continue for \(n\) days. He has to pass exam ...