Home >Java >javaTutorial >Check if date is between two other dates

Check if date is between two other dates

DDD
DDDOriginal
2024-09-19 06:20:271098browse

Check if date is between two other dates

A small method to check if a LocalDataTime is in a Range between to other LocalDateTime - Objects.

private boolean isInDateRange(
                        LocalDateTime upper,
                        LocalDateTime lower,
                        LocalDateTime toCheck) {
    var isUpper = toCheck.equals(upper);
    var isLower = toCheck.equals(lower);
    if (isLower || isUpper) {
        return true;
    }
    return toCheck.isBefore(upper) && toCheck.isAfter(lower);
}

The above is the detailed content of Check if date is between two other dates. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Power setNext article:Power set