Scroll between two dates

-3

I have two dates in milliseconds. I need to recover each day of that period to make an insert in the database. I thought about making a for every day of this period, but I have no idea how to do it!

    
asked by anonymous 08.01.2018 / 21:41

1 answer

0

You can do this by using the API from java 8:

long a = ...;
long b = ...;
Instant ia = Instant.ofEpochMilli(a);
Instant ib = Instant.ofEpochMilli(b);
LocalDate lda = LocalDateTime.ofInstant(ia, ZoneId.of("Z")).toLocalDate();
LocalDate ldb = LocalDateTime.ofInstant(ib, ZoneId.of("Z")).toLocalDate();

List<LocalDate> dates = new ArrayList<>();
for (LocalDate ld = lda; !ld.isAfter(ldb); ld = ld.plusDays(1)) {
    dates.add(ld);
}

See more about this on this other question .

    
08.01.2018 / 22:00