判断两个日期相差的时长

@param beginDate 起始日期
@param endDate 结束日期
@param unit 相差的单位：相差 天{@link DateUnit#DAY}、小时{@link DateUnit#HOUR} 等
@param isAbs 日期间隔是否只保留绝对值正数
@return 日期差
@since 3.3.1
162164
public static long between(Date beginDate, Date endDate, DateUnit unit, boolean isAbs) {
		return new DateBetween(beginDate, endDate, isAbs).between(unit);
	}
1213206
public static boolean isLastDayOfTheMonth(final Date date) {

    Date dateOfMonthsBack = getDateOfMonthsBack(-1, date);
    int dayOfMonth = getDayOfMonth(dateOfMonthsBack);
    Date dateOfDaysBack = getDateOfDaysBack(dayOfMonth, dateOfMonthsBack);
    return dateOfDaysBack.equals(date);
  }
145818
@Override
	public double getDaycountFraction(LocalDate startDate, LocalDate endDate) {
		if(startDate.isAfter(endDate)) {
			return -getDaycountFraction(endDate,startDate);
		}

		int periodIndexEndDate = Collections.binarySearch(periods, new Period(endDate, endDate, endDate, endDate));
		int periodIndexStartDate = Collections.binarySearch(periods, new Period(startDate, startDate, startDate, startDate));

		if(periodIndexEndDate < 0) {
			periodIndexEndDate		= -periodIndexEndDate-1;
		}
		if(periodIndexStartDate < 0) {
			periodIndexStartDate	= -periodIndexStartDate-1;
		} else {
			periodIndexStartDate	= periodIndexStartDate+1;
		}

		Period startDatePeriod = periods.get(periodIndexStartDate);
		Period endDatePeriod = periods.get(periodIndexEndDate);

		double periodFraction =
				getDaycount(startDate, startDatePeriod.getPeriodEnd()) / getDaycount(startDatePeriod.getPeriodStart(), startDatePeriod.getPeriodEnd())
				+
				getDaycount(endDatePeriod.getPeriodStart(), endDate) / getDaycount(endDatePeriod.getPeriodStart(), endDatePeriod.getPeriodEnd())
				+
				(periodIndexEndDate - periodIndexStartDate) - 1;

		return periodFraction / frequency;
	}
783458
public int getRemainingDays(String startDate, String endDate, Date currentDate) throws java.text.ParseException {
		DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");

		Calendar iterationEndDate = Calendar.getInstance();
		iterationEndDate.setTime(dateFormat.parse(endDate));

		Calendar iterationStartDate = Calendar.getInstance();
		iterationStartDate.setTime(dateFormat.parse(startDate));

		Calendar currentCalendarDate = Calendar.getInstance();
		currentCalendarDate.setTime(currentDate);

		int remainingDays = 0;

		if ((iterationStartDate.compareTo(currentCalendarDate) == 1)
				|| (iterationEndDate.compareTo(currentCalendarDate) == -1)) {

			return remainingDays;
		}

		while (iterationEndDate.compareTo(currentCalendarDate) == 1) {
			if ((currentCalendarDate.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY)
					&& (currentCalendarDate.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY)) {
				++remainingDays;
			}
			currentCalendarDate.add(Calendar.DAY_OF_MONTH, 1);
		}

		return remainingDays;
	}
899368
public static long getMillisDifference(Date startDate, Date endDate) {
		long startTime = startDate.getTime();
		long endTime = endDate.getTime();
		long diffTime = endTime - startTime;
		return diffTime;
	}
439790
public static long getDaysBetweenIgnoreTime(Date startDate, Date endDate) {
        startDate = getRoundedDay(startDate);
        endDate = getNextDay(endDate);
        return getBetweenDate(startDate, endDate);
    }
215558
public static DateRange range(Date start, Date end, final DateField unit) {
		return new DateRange(start, end, unit);
	}
508476
public static LinkedHashSet<String> yearAndQuarter(Date startDate, Date endDate) {
		if (startDate == null || endDate == null) {
			return new LinkedHashSet<String>(0);
		}
		return yearAndQuarter(startDate.getTime(), endDate.getTime());
	}
984215
public static long getMinutesDifference(Date startDate, Date endDate) {
		long startTime = startDate.getTime();
		long endTime = endDate.getTime();
		long diffTime = endTime - startTime;
		long diffInMinutes = TimeUnit.MILLISECONDS.toMinutes(diffTime);
		return diffInMinutes;
	}
327351
public static function formatted_dates($startObj, $endObj)
    {

        //Checking if end date is set
        $endDateIsset = true;
        if (isset($endObj->value)) {
            $endDateIsset = false;
        }

        $startTime = strtotime($startObj->value);
        $endTime = strtotime($endObj->value);

        $startMonth = date('M', $startTime);
        $startDayOfMonth = $startObj->DayOfMonth(true);
        $str = $startMonth . ' ' . $startDayOfMonth;

        if (date('Y-m-d', $startTime) == date('Y-m-d', $endTime)) {
            //one date - str. has already been written
        } else {
            //two dates

            if ($endDateIsset) {
                $endMonth = date('M', $endTime);
                $endDayOfMonth = $endObj->DayOfMonth(true);

                if ($startMonth == $endMonth) {
                    $str .= ' - ' . $endDayOfMonth;
                } else {
                    $str .= ' - ' . $endMonth . ' ' . $endDayOfMonth;
                }
            }
        }
        return $str;
    }
1206179
public static boolean isPeriodActive(final Date startDate, final Date endDate) {
		if (startDate == null && endDate == null) {
			return true;
		}
		if (startDate == null) {
			throw new JKException("START_DATE_CAN_NOT_BE_NULL");
		}
		if (endDate == null) {
			throw new JKException("END_DATE_CAN_NOT_BE_NULL");
		}
		if (compareTwoDates(startDate, endDate).equals(CompareDates.DATE1_GREATER_THAN_DATE2)) {
			throw new JKException("START_DATE_MUST_BE_BEFORE_END_DATE");
		}
		final boolean startLessThanCurrent = compareTwoDates(startDate, getSystemDate()).equals(CompareDates.DATE1_LESS_THAN_DATE2);
		final boolean endGreaterThanCurrent = compareTwoDates(endDate, getSystemDate()).equals(CompareDates.DATE1_GREATER_THAN_DATE2);
		return startLessThanCurrent && endGreaterThanCurrent;
	}
776857
private boolean isDate(Class clazz)
    {
        return clazz.isAssignableFrom(Date.class) || clazz.isAssignableFrom(java.sql.Date.class)
                || clazz.isAssignableFrom(Timestamp.class) || clazz.isAssignableFrom(Time.class)
                || clazz.isAssignableFrom(Calendar.class);
    }
34012
public static Date getRandomDate(Date begin, Date end) {
		return getRandomDate(begin, end, r);
	}
127446
public static Date beginOfDate(@NotNull final Date date) {
		return DateUtils.truncate(date, Calendar.DATE);
	}
184524
public static Date beginOfHour(@NotNull final Date date) {
		return DateUtils.truncate(date, Calendar.HOUR_OF_DAY);
	}
526437
public static boolean isOverlay(Date date1Start, Date date1End, Date date2Start, Date date2End) {
        return ((date1Start.getTime() >= date2Start.getTime()) && date1Start.getTime() <= date2End.getTime()) ||
                   ((date2Start.getTime() >= date1Start.getTime()) && date2Start.getTime() <= date1End.getTime());
    }
1169122
public static List<LocalDate> untilDays(LocalDate startDate, LocalDate endDate) {
        long until = startDate.until(endDate, ChronoUnit.DAYS) + 1;
        List<LocalDate> dates = new ArrayList<>();
        for (long i = 0; i < until; i++) {
            dates.add(startDate.plusDays(i));
        }
        return dates;
    }