Reputation: 351
I am looking for a way to list all days of a given month using Jodatime. It would be great to have concrete code sample.
Upvotes: 1
Views: 1808
Reputation: 351
Since I couldn't find answer to this question, I post the code here so someone can find use of it:
// 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;
}
Upvotes: 3