如何在格里高利历中减去两个日期?

时间:2014-11-16 02:26:54

标签: java date gregorian-calendar

如何编写一个函数来返回Gregorian Callendar中两个日期之间的天数?我应该用什么类型转换我的日期和方式?

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

1 个答案:

答案 0 :(得分:0)

使用GregorianCalendar对象,它是Calendar的子类:

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

Oracle docs