/* package whatever; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; import java.time.* ; import java.time.format.* ; import java.time.temporal.* ; /* Name of the class has to be "Main" only if the class is public. */ class Ideone { { DateTimeFormatter f = DateTimeFormatter.ofLocalizedDate( FormatStyle.FULL ).withLocale( Locale.US ) ; YearMonth ym = YearMonth.of( 2013 , Month.JANUARY ) ; LocalDate firstOfMonth = ym.atDay( 1 ) ; TemporalAdjuster ta = TemporalAdjusters.previousOrSame( DayOfWeek.MONDAY ) ; LocalDate previousOrSameMonday = firstOfMonth.with( ta ) ; LocalDate endOfMonth = ym.atEndOfMonth() ; LocalDate weekStart = previousOrSameMonday ; do { LocalDate weekStop = weekStart.plusDays( 6 ) ; // Set up the next loop. weekStart = weekStart.plusWeeks( 1 ) ; } while ( ! weekStart.isAfter( endOfMonth ) ) ; } }
Standard input is empty
Week: Monday, December 31, 2012 to Sunday, January 6, 2013 Week: Monday, January 7, 2013 to Sunday, January 13, 2013 Week: Monday, January 14, 2013 to Sunday, January 20, 2013 Week: Monday, January 21, 2013 to Sunday, January 27, 2013 Week: Monday, January 28, 2013 to Sunday, February 3, 2013