2015-01-06 30 views
1

獲得 的最佳途徑從 IntervalJoda-Time什麼是最佳方式? 從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); 
}