yongtaiyu

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

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;

 }

posted on 2012-06-28 15:55  yongtaiyu  阅读(687)  评论(0编辑  收藏  举报