技术交流群: 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;
}

最新文章

  1. Spring 下默认事务机制中@Transactional 无效的原因
  2. DbHelper为什么要用Using?
  3. Bellman_Ford
  4. 爱默生UPS并机系统:进入与退出操作方法
  5. 使用cocos2d-x 3.2下载图片资源小例子
  6. JAVA环境变量JAVA_HOME、CLASSPATH、PATH设置详解
  7. Hadoop HA的搭建
  8. mongodb学习(翻译1)
  9. mybatis深入理解之 # 与 $ 区别以及 sql 预编译
  10. Suricata默认规则集相关
  11. get.go
  12. 如何搭建SVN的客户端和使用
  13. 使用ThreadPoolExecutor进行多线程编程
  14. 微信公众号授权,支付,退款总结【shoucang】
  15. MyBatis笔记----MyBatis 入门经典的两个例子: XML 定义与注解定义
  16. GeoServer java.io.IOException: No such resource: generic.sld No such resource: generic.sld
  17. JVM内容梳理
  18. (11)学习笔记 ) ASP.NET CORE微服务 Micro-Service ---- Thrift高效通讯 (完结)
  19. POJ2516 Minimum Cost【最小费用最大流】
  20. 3D Slicer 4.7.0 VS 2010 Compile 编译

热门文章

  1. 【转载】每天一个Linux命令
  2. CopyTranslator-复制即翻译的外文辅助阅读翻译解决方案
  3. Python-Django框架学习笔记——第一课:Hello World
  4. Linux Mint,Ubuntu 18 ,Deepin15.7 安装mysql 没有提示输入密码,修改root用户密码过程
  5. vuejs使用组件的细节点
  6. 2017.10.24 Java 详解 JVM 工作原理和流程
  7. 2017.9.26 request请求参数用法
  8. MyBatis简单了解
  9. IE 8 下小心使用console.log()
  10. WEB相关背景知识(新手)