根据出生日期计年龄
2012-06-28 15:55
260 查看
public int GetAgeByBrithday(Date birthday){
int age=-1;
Date today=new Date();
int todayYear=today.getYear();
int todayMonth=today.getMonth()+1;
int todayDay=today.getDate();
int birthdayYear=birthday.getYear();
int birthdayMonth=birthday.getMonth();
int birthdayDay=birthday.getDate();
if(todayYear-birthdayYear<0)
{
FacesContext.getCurrentInstance().addMessage(null,
new FacesMessage("出生日期选择错误!"));
}
else
{
if(todayMonth*1-birthdayMonth*1<0)
{
age = (todayYear*1-birthdayYear*1)-1;
}
else
{
if(todayDay-birthdayDay>=0)
{//alert(thisDay+'-'+brithd+"_ddd");
age = (todayYear*1-birthdayYear*1);
}
else
{
age = (todayYear*1-birthdayYear*1)-1;
}
}
}
return age*1;
}
int age=-1;
Date today=new Date();
int todayYear=today.getYear();
int todayMonth=today.getMonth()+1;
int todayDay=today.getDate();
int birthdayYear=birthday.getYear();
int birthdayMonth=birthday.getMonth();
int birthdayDay=birthday.getDate();
if(todayYear-birthdayYear<0)
{
FacesContext.getCurrentInstance().addMessage(null,
new FacesMessage("出生日期选择错误!"));
}
else
{
if(todayMonth*1-birthdayMonth*1<0)
{
age = (todayYear*1-birthdayYear*1)-1;
}
else
{
if(todayDay-birthdayDay>=0)
{//alert(thisDay+'-'+brithd+"_ddd");
age = (todayYear*1-birthdayYear*1);
}
else
{
age = (todayYear*1-birthdayYear*1)-1;
}
}
}
return age*1;
}
相关文章推荐
- mysql根据出生日期计算年龄
- JS中根据出生日期计算年龄
- 在Excel中根据某一个单元格的出生日期自动精确计算年龄
- 根据出生日期计算宝宝的年龄,几岁几个月几天!
- SQL根据出生日期计算年龄的两种算法
- 根据身份证号码计算出生日期、年龄、性别(18位)
- python根据出生日期返回年龄的方法
- JS根据身份证号提取出生日期并计算年龄
- 根据出生日期计算年龄的代码
- JS:根据出生日期 得到年龄
- php根据出生日期计算年龄函数
- oracle根据出生日期计算年龄
- 根据填写的出生日期自动带出年龄
- EXCEL教程-根据身份证号得到年龄性别出生日期等信息
- 数据库里怎样根据出生日期计算精确年龄
- 根据出生日期计算年龄
- php根据出生日期生成年龄
- 根据出生日期计算年龄的sql各种数据库写法
- php根据出生日期获取年龄,生日数据类型为date型
- js 根据出生日期获得年龄