io.github.jiawade.tool.utils.DateUtils Maven / Gradle / Ivy
The newest version!
package io.github.jiawade.tool.utils;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class DateUtils {
public static List getDatesBetweenTwoDays(LocalDate startDate, LocalDate endDate) {
long numOfDaysBetween = ChronoUnit.DAYS.between(startDate, endDate.plusDays(1));
return IntStream.iterate(0, i -> i + 1)
.limit(numOfDaysBetween)
.mapToObj(startDate::plusDays)
.collect(Collectors.toCollection(ArrayList::new));
}
public static long getMonthsBetweenTwoDays(LocalDate startDate, LocalDate endDate) {
return ChronoUnit.MONTHS.between(startDate, endDate);
}
}