2014-11-16 99 views
0

如何編寫一個函數,它返回Gregorian Callendar中兩個日期之間的天數?我應該怎樣轉換我的日期和方式?如何在GregorianCallendar中減去兩個日期?

public int substractDate(GregorianCalendar beginningDate, GregorianCalendar endingDate){ 
      return dif; 
     } 
+0

可能重複[爪哇 - 從日期減去天(http://stackoverflow.com/questions/ 12930134/java-subtract-days-date) –

回答

0

使用GregorianCalendar對象是Calendar的一個子類:的

String dayPattern = "DD"; 
    SimpleDateFormat days = new SimpleDateFormat(dayPattern); 
    return Integer.parseInt(days.format(endingDate.getTimeInMillis()-beginningDate.getTimeInMillis())); 

Oracle docs

+0

工作,謝謝 – pawkondr