CardUtil算出当前身份证持有者的性别和年龄
|
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算出当前身份证持有者的性别和年龄的更多相关文章
- js脚本根据身份证号获取性别、年龄、家庭地址、生日
做项目测试时需要根据身份证号获取其信息,也不想调接口,就自己在本地通过收集资料整合了一个
- js 根据身份证号获取性别,年龄,等
$(function(){ $("#corpOwnerIdno").blur(function(){ //获取输入身份证号码 ...
- sqlalchemy 模型中添加根据身份证号计算性别和年龄
class Users(Base, BaseMixin): username = Column(String(24)) id_Num = Column(String(18) ) # 身份证号码 @pr ...
- java根据身份证号和获取用户年龄和性别的工具类
import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util ...
- PHP通过身份证号码获取性别、出生日期、年龄等信息
$sex = substr($idcard, (strlen($idcard)==18 ? -2 : -1), 1) % 2 ? '1' : '2'; //18位身份证取性别,倒数第二位奇数是男,偶数 ...
- Excel通过身份证获取出生年月,性别,年龄,生肖,星座,省份等信息总结归纳
Excel通过身份证获取出生年月,性别,年龄,生肖,星座,省份等信息总结归纳 早期的身份证号码为15位数字,现在使用的身份证号码为18位数字,它们的含义如下:(1)15位:1-6位为地区代码,7-8位 ...
- java 根据身份证号码获取出生日期、性别、年龄
1.情景展示 如何根据身份证号,计算出出生日期.性别.年龄? 2.解决方案 从网上找的别人的,因为并没有实际用到,所以并未对其优化! /** * 通过身份证号码获取出生日期.性别.年龄 * @pa ...
- iOS之由身份证号返回性别
该博文出自:http://www.cnblogs.com/yang-guang-girl/p/5683454.html - (void)viewDidLoad { [super viewDidLoad ...
- 【代码笔记】iOS-由身份证号码返回性别
一,代码. - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. ...
随机推荐
- jmter脚本运行结果实时监控
一.背景 我们很多时候在使用JMeter做性能测试,我们很难及时察看压测过程中应用的性能状况,总是需要等到测试完成后去看Report 二.解决方案 JMeter引入Backend Listener,用 ...
- php构建型模式(Builder pattern)
练代码,增加了调用时的输出. <?php /* The builder pattern separates the construction of a complex object from i ...
- 洛谷 P3071 [USACO13JAN]座位Seating(线段树)
P3071 [USACO13JAN]座位Seating 题目链接 思路: 一开始把题给读错了浪费了好多时间呜呜呜. 因为第二个撤离操作是区间修改,所以我们可以想到用线段树来做.对于第一个操作,我们只需 ...
- springboot-注解-@Repository、@Service、@Controller 和 @Component
Spring 2.5 中除了提供 @Component 注释外,还定义了几个拥有特殊语义的注释,它们分别是:@Repository.@Service 和 @Controller.在目前的 Spring ...
- spring Cloud Feign作为HTTP客户端调用远程HTTP服务
在Spring Cloud Netflix栈中,各个微服务都是以HTTP接口的形式暴露自身服务的,因此在调用远程服务时就必须使用HTTP客户端.我们可以使用JDK原生的URLConnection.Ap ...
- Day01~15 - Python语言基础
Day01 - 初识Python Python简介 - Python的历史 / Python的优缺点 / Python的应用领域 搭建编程环境 - Windows环境 / Linux环境 / MacO ...
- Eclipse 常用快捷键——IDEA 常用快捷键
Eclipse 常用快捷键 熟练 单选注释 ctrl + / 多行注释 ctrl + shift + / 向下复制一行 (Duplicate Lines) ctrl+alt+down 删除一行或选中行 ...
- python基础知识字符串与元祖
https://blog.csdn.net/hahaha_yan/article/details/78905495 一.字符串的类型 ##表示字符串: 'i like the world' " ...
- MIME Type介绍 Content-Type 各种定义
多用途互联网邮件扩展(MIME,Multipurpose Internet Mail Extensions)是一个互联网标准,它扩展了电子邮件标准,使其能够支持非ASCII字符.二进制格式附件等多种格 ...
- 通过100张图一步步理解CNN
https://blog.csdn.net/v_july_v/article/details/79434745 Youtube上迄今为止最好的卷积神经网络快速入门教程 https://www.bili ...