How to substract two dates in GregorianCallendar?

143 views Asked by At

How to write a function which returns number of days between two dates in Gregorian Callendar? What type should I convert my dates and how?

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

There are 1 answers

0
Threadid On BEST ANSWER

Use GregorianCalendar object which is a subclass of Calendar:

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

Oracle docs