程式範例, 參考如下囉 :
程式碼
Date vTomKuoDate1 = new Date(); Date vTomKuoDate2 = new SimpleDateFormat ("yyyyMMdd").parse("20140131"); long vBetween = vTomKuoDate2.getTime() - vTomKuoDate1.getTime(); System.out.println("差異秒數: " + vBetween); // 差異秒數: -2100652011 int vDays = (int)Math.floor(vBetween/(24d*60d*60d*1000d)); System.out.println("差異天數: " + vDays ); // 差異天數: -25