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;
}
java身份证计算年龄的更多相关文章
- sql 身份证计算年龄和性别
IdentityNumber 是身份证号 年龄: ,), GETDATE()) / 365.25) as '推荐人年龄', 15位的身份证计算年龄: case when b.IdentityNumbe ...
- Java生日计算年龄工具
package com.web.backend.util; import java.util.Calendar;import java.util.Date; /** * @Author: SongZS ...
- SQL语句通过身份证号计算年龄
SQL语句通过身份证号计算年龄 1.截取身份证号上的出生日期 身份证一般为18位数和15位数 18位数身份证的第7-10位数是出生年份,第11-14位数是出生月日,所以18位身份证的年龄计算如下 su ...
- Java 根据年月日精确计算年龄
import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; /** * Created b ...
- Java 计算年龄
public static String getAgeTxt(String birthTime,String beginTime,int level){ if(StringUtils.isBlank( ...
- oracle根据身份证号码 计算年龄、性别
一.Oracle根据身份证判断性别: 女生身份证: 431382198103246985 男生身份证: 150921197208173492 SQL语句如下: select decode(mod ...
- Java 根据出生日期计算年龄
1.把出生日期字符串转换为日期格式. public static Date parse(String strDate) throws ParseException { SimpleDateFormat ...
- java 根据生日计算年龄 Java问题通用解决代码
根据生日计算年龄可以通过Calendar实现.最简单可以考虑get(Calendar.DAY_OF_YEAR)来简单修正年龄,但是遇到生日在闰年的2月29之后,或者今年是闰年的2月29之后可能出现计算 ...
- java计算年龄
精确到天计算年龄 public static int getAgeByCardId(String card) throws Exception { Integer len = card.length( ...
随机推荐
- Spring Cloud入门程序
本文手把手教你,做出第一个Spring Cloud程序,Eureka的简单入门使用 1.创建Spring Starter Project工程 点击next,添加项目名 2.引入Spring Cloud ...
- Node.js-Webstorm2018配置nodejs
网上都是webstorm老版本的设置方法!根本就找不到以下配置项: 下面介绍2018版的配置方式.功能:使webstrom支持node.js语法检测及语法提示! 例如:配置前,没有任何提示 配置后 配 ...
- VS2013配置OpenGL
创建win32项目而不要创建空项目,否则会出现文件包含问题.
- Selenium入门系列1 打开浏览器访问网页,退出浏览器
对于功能自动化的理解就是用测试工具替代手工.手工怎么操作的,工具也如何操作. 手工测试:在前置条件下,执行一定的操作步骤>与预期结果对比 功能自动化:在前置条件下,识别对象 >操作对象&g ...
- firewalld 使用简介
学习apache安装的时候需要打开80端口,由于centos 7版本以后默认使用firewalld后,网上关于iptables的设置方法已经不管用了,想着反正iptable也不会用,索性直接搬官方文档 ...
- centos install rtl8188ce driver
1.导入公钥,注意大小写. rpm --import http://elrepo.org/RPM-GPG-KEY-elrepo.org 2.安装ELRepo库. rpm -Uvh http://elr ...
- Http之基础
简介 HTTP协议(HyperText Transfer Protocol,超文本传输协议)是因特网上应用最为广泛的一种网络传输协议,所有的WWW文件都必须遵守这个标准. HTTP是一个基于TCP/I ...
- google detection
paper: Scalable, High-Quality Object Detection ILSVRC14上,detection刷到55.7%的MAP,google插入的地方,别人倍感压力啊. 总 ...
- LeetCode567. Permutation in String
Given two strings s1 and s2, write a function to return true if s2 contains the permutation of s1. I ...
- poj_2689_Prime Distance
The branch of mathematics called number theory is about properties of numbers. One of the areas that ...