public static void main(String[] args) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
try {
Long current = sdf.parse("2013/01/01").getTime();
Long birth = sdf.parse("1990/01/01").getTime();
Long age = (current-birth)/(1000*60*60*24)/365;
System.out.println(age);
} catch (ParseException e) {
e.printStackTrace();
}
}结果:23 public static void main(String[] args) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
try {
Long current = sdf.parse("2013/01/01").getTime();
Long birth = sdf.parse("1990/01/01").getTime();
Long age = (current-birth)/(1000*60*60*24*365);
System.out.println(age);
} catch (ParseException e) {
e.printStackTrace();
}
}结果:493 public static void main(String[] args) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
try {
Long current = sdf.parse("2013/01/01").getTime();
Long birth = sdf.parse("1990/01/01").getTime();
Long age = (current-birth)/(1000*60*60*24);
System.out.println((int)(age/365));
} catch (ParseException e) {
e.printStackTrace();
}
}结果:23什么情况.....
SimpleDateFormat
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
try {
Long current = sdf.parse("2013/01/01").getTime();
Long birth = sdf.parse("1990/01/01").getTime();
Long age = (current-birth)/(1000*60*60*24)/365;
System.out.println(age);
} catch (ParseException e) {
e.printStackTrace();
}
}结果:23 public static void main(String[] args) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
try {
Long current = sdf.parse("2013/01/01").getTime();
Long birth = sdf.parse("1990/01/01").getTime();
Long age = (current-birth)/(1000*60*60*24*365);
System.out.println(age);
} catch (ParseException e) {
e.printStackTrace();
}
}结果:493 public static void main(String[] args) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
try {
Long current = sdf.parse("2013/01/01").getTime();
Long birth = sdf.parse("1990/01/01").getTime();
Long age = (current-birth)/(1000*60*60*24);
System.out.println((int)(age/365));
} catch (ParseException e) {
e.printStackTrace();
}
}结果:23什么情况.....
SimpleDateFormat
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货