Java Calendar Day dayDistance(Calendar date1, Calendar date2)

Here you can find the source of dayDistance(Calendar date1, Calendar date2)

Description

day Distance

License

Open Source License

Declaration

public static int dayDistance(Calendar date1, Calendar date2) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Calendar;

public class Main {
    public static int dayDistance(Calendar date1, Calendar date2) {
        int noDays = 0;

        if (date1.before(date2)) {
            Calendar temp = Calendar.getInstance();
            temp.setTimeInMillis(date1.getTimeInMillis());
            while (temp.before(date2)) {
                temp.add(Calendar.DATE, 1);
                noDays++;/*from w  ww. jav a  2 s. com*/
            }
        } else if (date1.after(date2)) {
            Calendar temp = Calendar.getInstance();
            temp.setTimeInMillis(date2.getTimeInMillis());
            while (temp.before(date1)) {
                temp.add(Calendar.DATE, 1);
                noDays++;
            }
        }
        return noDays;
    }
}

Related

  1. day(Calendar calendar)
  2. day(Calendar date)
  3. day2date(int day, Calendar cal)
  4. dayBegin(Calendar cal)
  5. dayBegin(Calendar calendar)
  6. dayEndTime(Calendar calendar)
  7. dayFloor(Calendar calendar)
  8. dayIterable(Calendar from, Calendar to)
  9. dayMarkToCalendar(int day)