//年龄计算
public int calcAge(String strBirthday,String startDate)
{
int age = 0;
DateFormat df_cn = new SimpleDateFormat("yyyy-MM-dd");
try {
Calendar birthday = Calendar.getInstance();
birthday.setTime(df_cn.parse(strBirthday));
Calendar today = Calendar.getInstance();
today.setTime(df_cn.parse(startDate));
age = today.get(1) - birthday.get(1);
if (today.get(2) <= birthday.get(2)) {
if (today.get(2) == birthday.get(2)) {
if (today.get(5) < birthday.get(5))
age--;
}
else
age--;
}
}
catch (Exception e)
{
e.printStackTrace();
}
return age;
}
java年龄计算
最新推荐文章于 2023-04-20 10:49:03 发布