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!
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!
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 .