2013-04-20 81 views

回答

2

因爲我無法找到這個問題的答案,我張貼在這裏的代碼,以便有人能找到利用它:

// set your own print format here 
private static final DateTimeFormatter DF=DateTimeFormat.forPattern("dd/MM/yyyy"); 

    private List<String> createMonthLabels(LocalDate month) { 
    // add labels 
    List<String> daysInMonthLabels = new ArrayList<String>(); 
    LocalDate firstDay = month.withDayOfMonth(1); 
    LocalDate nextMonthFirstDay = firstDay.plusMonths(1); 
    while (firstDay.isBefore(nextMonthFirstDay)) { 
     daysInMonthLabels.add(DF.print(firstDay)); 
     firstDay = firstDay.plusDays(1); 
    } 

    return daysInMonthLabels; 
} 
+1

不要使用日期時間/ datemidnight(他們是在準確的時間點)時你的意思只是日期,這在概念上是錯誤的。用'LocalDate'替換DateMidnight/DateTime,你的答案很好。 – leonbloy 2013-04-21 13:48:08

+0

Tnx @leonbloy,請參閱我的編輯。 – 2013-04-22 07:55:56

相關問題