yld77

  

public static String getAge(String str) throws Exception{
ArrayList<Integer> bir = new ArrayList<Integer>();
int i = 0;
Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH)+1;
int date = c.get(Calendar.DATE);
int age = 0;
//System.out.println(year+" "+month+" "+date+"");
try {
str = str.trim();
while(str.trim().charAt(0) == \'-\'){
str = str.substring(1);
}
String temp[] = str.trim().split("-");
if(temp.length == 3){
for(;i < 3; i++){
bir.add(Integer.parseInt(temp[i]));
}
}
if(year - bir.get(0) > 0){
age = year - bir.get(0) - 1;
if(month >= bir.get(1) ){
if(date >= bir.get(2)){
age+=1;
}
}
}
}catch (Exception e){
System.out.println("无法解析为年月日的结构");
throw e;
}
return age+" ";

}

分类:

技术点:

相关文章:

  • 2021-10-06
  • 2021-11-17
  • 2021-11-13
  • 2021-11-30
  • 2021-09-16
  • 2021-09-16
  • 2021-09-16
  • 2021-09-12
猜你喜欢
  • 2018-01-06
  • 2021-11-13
  • 2021-11-13
  • 2021-11-30
  • 2021-09-16
  • 2021-09-12
  • 2021-09-12
相关资源
相似解决方案