使用Joda-Time从List<LocalDate>
获取Interval
的最佳方法是什么?
例如:
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
答案 0 :(得分:1)
尝试:
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);
}