I want to generate a list of dates + times between two dates in format 2018-01-31T17:20:30Z(or "yyyy-MM-dd'T'HH:mm:ss'Z'") in increments of 60 seconds.
So far, I could generate all dates between two dates using an object LocalDate:
public class DateRange implements Iterable<LocalDate> {
private final LocalDate startDate;
private final LocalDate endDate;
public DateRange(LocalDate startDate, LocalDate endDate) {
this.startDate = startDate;
this.endDate = endDate;
}
@Override
public Iterator<LocalDate> iterator() {
return stream().iterator();
}
public Stream<LocalDate> stream() {
return Stream.iterate(startDate, d -> d.plusDays(1))
.limit(ChronoUnit.DAYS.between(startDate, endDate) + 1);
}
}
Given a start and end date, this generates Iterableall dates between them.
However, I would like to change this so that it generates every step of 60 seconds using the object LocalDateTime(i.e. instead of generating one value per day, it would generate 1440 values, because 60 minutes per hour once 24 hours a day, if the initial and the final time was only one day)
thank
source
share