-3

I want to get all the dates of a month in a list so i can show all the dates from that month on a JSF page. When the month changes the amount of dates has to change accordingly.

I Use Java 8 LocalDate.

How can i best do that?

  • Why not use JSF calendar? https://www.primefaces.org/showcase/ui/input/calendar.xhtml – actunderdc May 25 '18 at 08:18
  • google jsf-datepicker-example – Kid101 May 25 '18 at 08:18
  • Hi thanks for the comments. But it's not just the calendar widget i need. I need to put the dates into the first column of a datatable – Wim Van Geyt May 25 '18 at 08:25
  • "When the month changes the amount of dates has to change" > you say that you already want all the dates of all the months. How can a month change after you already have them all? I think you're not describing correctly what's your problem. – kumesana May 25 '18 at 08:44
  • @kumesana I've edited my question a bit. – Wim Van Geyt May 25 '18 at 08:46
  • Possible duplicate of [Number of days in particular month of particular year?](https://stackoverflow.com/questions/8940438/number-of-days-in-particular-month-of-particular-year) – Jeppz May 25 '18 at 08:54

1 Answers1

0

I'm not sure how can one need to put all the dates of the month in a database, but here's a way to get the List of all the dates of the current month:

    LocalDate date = LocalDate.now().withDayOfMonth(1);
    LocalDate end = date.plusMonths(1);

    List<LocalDate> dates = new ArrayList<>();
    while(date.isBefore(end)) {
        dates.add(date);
        date = date.plusDays(1);
    }
kumesana
  • 2,495
  • 1
  • 9
  • 10