通过出生年月得到当前年龄java代码实例
来源:互联网 发布:淘宝上怎么找餐饮发票 编辑:程序博客网 时间:2024/06/08 17:50
此java示例是通过输入出生年龄计算年龄的代码:
import java.text.SimpleDateFormat;import java.util.Date;public class Test { public static int getAgeByBirthDay(String birthDay){ if (birthDay == null || birthDay.length()<4) { return 0; } SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); //得到当前的年份 String cYear = sdf.format(new Date()).substring(0,4); String cMouth = sdf.format(new Date()).substring(5,7); String cDay = sdf.format(new Date()).substring(8,10); //得到生日年份 String birth_Year = birthDay .substring(0,4); String birth_Mouth = birthDay .substring(5,7); String birth_Day = birthDay .substring(8,10); int age = Integer.parseInt(cYear) - Integer.parseInt(birth_Year); if ((Integer.parseInt(cMouth) - Integer.parseInt(birth_Mouth))<0) { age=age-1; }else if ((Integer.parseInt(cMouth) - Integer.parseInt(birth_Mouth))==0) { if ( (Integer.parseInt(cDay) - Integer.parseInt(birth_Day))>0) { age=age-1; }else { age = Integer.parseInt(cYear) - Integer.parseInt(birth_Year); } }else if ((Integer.parseInt(cMouth) - Integer.parseInt(birth_Mouth))>0) { age = Integer.parseInt(cYear) - Integer.parseInt(birth_Year); } return age; } public static void main(String[] args) { Test test=new Test(); int age=test.getAgeByBirthDay("2015-05-11");//输入出生年份; System.out.println(age); }}
0 0
- 通过出生年月得到当前年龄java代码实例
- 关于通过出生年月获取年龄的java代码
- java根据出生年月计算年龄
- String类型出生年月计算年龄
- excel 根据身份证号码自动提取出生年月、性别、年龄的方法实例
- sql server出生年月减去退休年月 计算年龄
- 通过出生年月日计算年龄
- 通过出生年月日计算年龄
- 在EXCEL中根据身份证号码计算年龄、出生年月、性别
- java获取当前年月
- java 通过身份证号码得到用户的性别年龄
- 通过出生年月,分组查询人口年龄段人数
- java通过当前时间得到上个月时间
- WCF医院管理系统技术解析小功能(一)输入身份证验证年龄、性别、出生年月
- Java获取当前的年月
- 出生年月转年龄
- 学生的出生年月
- 通过身份证分析出生年月日、性别、年龄的SQL语句
- linux下让tomcat以service方式运行
- 盖茨比有什么了不起
- Failed to read auto-increment value from the storage engine in MySQL
- 使用VS开发 Node.js指南
- SSH之开发struts组件(实践)
- 通过出生年月得到当前年龄java代码实例
- c语言中static 函数和普通函数的区别?
- 大型网站架构演化历程
- CentOS 7.0编译安装Nginx1.6.0+MySQL5.6.19+PHP5.5.14方法
- self = [super init]
- 浏览器跳安卓应用
- JdbcUtils工具的抽取
- C#压缩解压缩源码
- 7.29数据库函数