Java Utililty Methods Calendar Between

List of utility methods to do Calendar Between

Description

The list of methods to do Calendar Between are organized into topic(s).

Method

intdaysBetween(Calendar early, Calendar late)
Returns the days between two dates.
return (int) (toJulian(late) - toJulian(early));
intdaysBetween(Calendar early, Calendar late)
days Between
return (int) (toJulian(late) - toJulian(early));
intdaysBetween(Calendar fromCalendar, Calendar untilCalendar)
days Between
return julianDay(untilCalendar.get(Calendar.YEAR), untilCalendar.get(Calendar.MONTH) + 1,
        untilCalendar.get(Calendar.DAY_OF_MONTH))
        - julianDay(fromCalendar.get(Calendar.YEAR), fromCalendar.get(Calendar.MONTH) + 1,
                fromCalendar.get(Calendar.DAY_OF_MONTH));
longdaysBetween(Calendar fromDate, Calendar toDate)
days Between
return Math.round((toDate.getTimeInMillis() - fromDate.getTimeInMillis()) / (1000 * 60 * 60 * 24));
longdaysBetween(Calendar start, Calendar end)
days Between
GregorianCalendar startDate = new GregorianCalendar(Locale.getDefault());
GregorianCalendar endDate = new GregorianCalendar(Locale.getDefault());
startDate.setGregorianChange(new Date(Long.MAX_VALUE));
endDate.setGregorianChange(new Date(Long.MAX_VALUE));
startDate.setTime(start.getTime());
endDate.setTime(end.getTime());
startDate.set(Calendar.HOUR_OF_DAY, 12);
endDate.set(Calendar.HOUR_OF_DAY, 12);
...
intdaysBetween(Calendar startTime, Calendar endTime)
days Between
if (startTime == null) {
    throw new IllegalArgumentException("startTime is null");
if (endTime == null) {
    throw new IllegalArgumentException("endTime is null");
if (startTime.compareTo(endTime) > 0) {
    throw new IllegalArgumentException("endTime is before the startTime");
...
intdaysBetween(final Calendar cal1, final Calendar cal2)
days Between
final Calendar from, to;
boolean positive = true;
if (cal1.getTimeInMillis() < cal2.getTimeInMillis()) {
    from = cal1;
    to = cal2;
} else {
    from = cal2;
    to = cal1;
...
longdaysBetween(final Calendar startDate, final Calendar endDate)
days Between
long days = 0;
while (endDate.after(startDate)) {
    endDate.add(Calendar.DATE, -1);
    ++days;
return days;
longdaysBetween(final Calendar startDate, final Calendar endDate)
Determines the number of days between two dates in Calendar objects
Calendar sDate = (Calendar) startDate.clone();
long daysBetween = 0;
int y1 = sDate.get(Calendar.YEAR);
int y2 = endDate.get(Calendar.YEAR);
int m1 = sDate.get(Calendar.MONTH);
int m2 = endDate.get(Calendar.MONTH);
while (((y2 - y1) * 12 + (m2 - m1)) > 12) {
    if (sDate.get(Calendar.MONTH) == Calendar.JANUARY
...
longdaysBetweenCalendarDates(final Calendar firstDate, final Calendar secondDate)
days Between Calendar Dates
return ((secondDate.getTimeInMillis() - firstDate.getTimeInMillis()) / (1000 * 60 * 60 * 24));