java根據出生日期計算年齡


/**
  * @author jerry.chen
  * @param brithday
  * @return
  * @throws ParseException
  *             根據生日獲取年齡;
  */
 public static int getCurrentAgeByBirthdate(String brithday)
   throws ParseException, Exception {
  try {
   Calendar calendar = Calendar.getInstance();
   SimpleDateFormat formatDate = new SimpleDateFormat(FORMATE_DATE_STR);
   String currentTime = formatDate.format(calendar.getTime());
   Date today = formatDate.parse(currentTime);
   Date brithDay = formatDate.parse(brithday);

   return today.getYear() - brithDay.getYear();
  } catch (Exception e) {
   return 0;
  }
 }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM