To get the range of the week, just create an object pointing to the first and last day of the week, then just pull the month out of it.
int weekOfYear = 32; LocalDate firstDay = new LocalDate().withWeekOfWeekyear(weekOfYear).withDayOfWeek(1); LocalDate lastDay = new LocalDate().withWeekOfWeekyear(weekOfYear).withDayOfWeek(7); System.out.println("Week of Year "+weekOfYear+"; "+firstDay.toString("d MMM")+" - "+lastDay.toString("d MMM"));
You can also highlight the following day:
int weekStart = firstDay.getDayOfMonth(); int weekEnd = lastDay.getDayOfMonth();
Then you can use the same technique to get weeks per month.
int firstWeekInMonth = new LocalDate().withMonthOfYear(month).withDayOfMonth(1).getWeekOfYear(); int lastWeekInMonth = new LocalDate().withMonthOfYear(month).dayOfMonth().withMaximalValue().getWeekOfYear();
You can probably limit the start and end time of your stay within the month range, otherwise you could get things like September 30 - 5.
Joeri hendrickx
source share