从 Interval 获取 List<LocalDate> 的最佳方法
Best way to get List<LocalDate> from Interval
从具有 Joda-Time 的 Interval
获得 List<LocalDate>
的最佳方法是什么?
例如:
Interval interval = new Interval(new LocalDate(2015, 01, 01).toDate().getTime(), new LocalDate(2015, 01, 05).toDate().getTime()); //Maybe not the best way to create an Interval...
List<LocalDate> listLocalDate = getListLocalDateFromInterval(interval);
for (LocalDate localDate : listLocalDate) {
System.out.println(localDate);
}
预期结果:
2015-01-01
2015-01-02
2015-01-03
2015-01-04
2015-01-05
尝试:
LocalDate from = interval.getStart().toLocalDate();
LocalDate to = interval.getEnd().toLocalDate();
List<LocalDate> lds = new ArrayList<>(Days.daysBetween(from, to).getDays());
for(LocalDate c = from ; c.isBefore(to) || c.isEqual(to) ;
c = c.plusDays(1)) {
lds.add(c);
}
从具有 Joda-Time 的 Interval
获得 List<LocalDate>
的最佳方法是什么?
例如:
Interval interval = new Interval(new LocalDate(2015, 01, 01).toDate().getTime(), new LocalDate(2015, 01, 05).toDate().getTime()); //Maybe not the best way to create an Interval...
List<LocalDate> listLocalDate = getListLocalDateFromInterval(interval);
for (LocalDate localDate : listLocalDate) {
System.out.println(localDate);
}
预期结果:
2015-01-01
2015-01-02
2015-01-03
2015-01-04
2015-01-05
尝试:
LocalDate from = interval.getStart().toLocalDate();
LocalDate to = interval.getEnd().toLocalDate();
List<LocalDate> lds = new ArrayList<>(Days.daysBetween(from, to).getDays());
for(LocalDate c = from ; c.isBefore(to) || c.isEqual(to) ;
c = c.plusDays(1)) {
lds.add(c);
}