private static void DatetimeDiff(Date begin, Date end) {
long diff = 0;
try {
diff = (end.getTime() - begin.getTime());// 得到两者的毫秒数
} catch (Exception ex) {
ex.printStackTrace();
}
long day = diff / (24 * 60 * 60 * 1000);
long hour = (diff / (60 * 60 * 1000) - day * 24);
long min = ((diff / (60 * 1000)) - day * 24 * 60 - hour * 60);
long s = (diff / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60);
long ms = (diff - day * 24 * 60 * 60 * 1000 - hour * 60 * 60 * 1000 - min * 60 * 1000 - s * 1000);
System.out.println(day + "天" + hour + "小时" + min + "分" + s + "秒" + ms + "毫秒");
}
这样常用而又标准的函数,java就应该集成在平台里。