计算两个年龄差值的方法
public class Practice {
public static void main(String[] args) throws ParseException {
reckonAge(“2015-08-18”);
}
public static void reckonAge(String birthday1,String birthday2) throws ParseException {
DateFormat df = new SimpleDateFormat(“yyyy-MM-dd”);
//将两个日期转换成毫秒进行计算
long firstDate = df.parse(birthday1).getTime();
long secondDate = df.parse(birthday2).getTime();
//计算
long result = Math.abs(firstDate-secondDate
);
int age = (int) (result/1000/60/60/24/30);
int yu = age%12;
int zheng = age/12;
String newAge = zheng+“岁”+yu+“月”;
System.out.println(newAge);
}
}