1: import java.util.Date;
2:
3: public class ShowTimeInterval{
4: public void ShowTimeInterval(Date date1, Date date2) {
5: long lDate1 = date1.getTime();
6: long lDate2 = date2.getTime();
7: long diff = (lDate1 < lDate2) ? (lDate2 - lDate1) : (lDate1 - lDate2);
8: long day = diff / (24 * 60 * 60 * 1000);
9: long hour = diff / (60 * 60 * 1000) - day * 24;
10: long min = diff / (60 * 1000) - day * 24 * 60 - hour * 60;
11: long sec = diff / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60;
12: System.out.println("date1 与 date2 相差 " + day + "天" + hour + "小时" + min + "分" + sec + "秒");
13: }
14: }