//三十分钟取一个时间
private List<LocalDateTime> getThirtyMinutesDatesBetweenUsingJava8(LocalDateTime startDateTime, LocalDateTime endDateTime) {
long numOfDaysBetween = ChronoUnit.MINUTES.between(startDateTime, endDateTime.plusMinutes(60)) / 30 - 1;
return IntStream.iterate(0, i -> i + 30)
.limit(numOfDaysBetween)
.mapToObj(startDateTime::plusMinutes)
.collect(Collectors.toList());
}
//十分钟取一个时间
private List<LocalDateTime> getTenMinutesDatesBetweenUsingJava8(LocalDateTime startDateTime, LocalDateTime endDateTime) {
long numOfDaysBetween = ChronoUnit.MINUTES.between(startDateTime, endDateTime.plusMinutes(20)) / 10 - 1;
return IntStream.iterate(0, i -> i + 10)
.limit(numOfDaysBetween)
.mapToObj(startDateTime::plusMinutes)
.collect(Collectors.toList());
}
//一分钟取一个时间
public static List<LocalDateTime> getMinutesDatesBetweenUsingJava8(LocalDateTime startDateTime, LocalDateTime endDateTime) {
long numOfDaysBetween = ChronoUnit.MINUTES.between(startDateTime, endDateTime.plusMinutes(1));
return IntStream.iterate(0, i -> i + 1)
.limit(numOfDaysBetween)
.mapToObj(startDateTime::plusMinutes)
.collect(Collectors.toList());
}
两个日期时间中,按指定分钟数间隔取所有时间
最新推荐文章于 2023-09-08 16:31:14 发布