You have a YearMonth object. For each day of the month, you can call atDay(dayOfMonth) to return LocalDate on that particular day of the month. Using LocalDate you can call:
Thus, you must modify your Dayes list to hold LocalDate instead of Integer s, and then you can have, for example:
YearMonth yearMonthObject = YearMonth.of(year, month); int daysOfCurrentMonth = yearMonthObject.lengthOfMonth(); ArrayList<LocalDate> dayes = new ArrayList<LocalDate>(); for(int i = 1; i <= daysOfCurrentMonth; i++){ dayes.add(yearMonthObject.atDay(i)); } dayes.forEach(value -> System.out.println(value.getDayOfMonth() + " " + value.getDayOfWeek()));
It will print every day of this month, followed by the corresponding day of the week.
As a note, you can get the actual display value for the day of the week (instead of the name() listing, as mentioned above) by calling getDisplayName(style, locale) . The style describes how to write days (long form, short form ...), and the locale is the language used for the display name. An example is:
value.getDayOfWeek().getDisplayName(TextStyle.FULL, Locale.ENGLISH)
which will display the full text of the day of the week in English. Output example on 04/2016 with the above change:
1 Friday 2 Saturday 3 Sunday 4 Monday 5 Tuesday
source share