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;
}