/** * Returns the day-of-week that is the specified number of days before this one. * <p> * The calculation rolls around the start of the year from Monday to Sunday. * The specified period may be negative. * <p> * This instance is immutable and unaffected by this method call. * * @param days the days to subtract, positive or negative * @return the resulting day-of-week, not null */ public DayOfWeek minus(long days) { return plus(-(days % 7)); }
/** * Returns the day-of-week that is the specified number of days before this one. * <p> * The calculation rolls around the start of the year from Monday to Sunday. * The specified period may be negative. * <p> * This instance is immutable and unaffected by this method call. * * @param days the days to subtract, positive or negative * @return the resulting day-of-week, not null */ public DayOfWeek minus(long days) { return plus(-(days % 7)); }
/** * Obtains an instance of {@code WeekFields} appropriate for a locale. * <p> * This will look up appropriate values from the provider of localization data. * * @param locale the locale to use, not null * @return the week-definition, not null */ public static WeekFields of(Locale locale) { Jdk8Methods.requireNonNull(locale, "locale"); locale = new Locale(locale.getLanguage(), locale.getCountry()); // elminate variants // obtain these from GregorianCalendar for now GregorianCalendar gcal = new GregorianCalendar(locale); int calDow = gcal.getFirstDayOfWeek(); DayOfWeek dow = DayOfWeek.SUNDAY.plus(calDow - 1); int minDays = gcal.getMinimalDaysInFirstWeek(); return WeekFields.of(dow, minDays); }
/** * Obtains an instance of {@code WeekFields} appropriate for a locale. * <p> * This will look up appropriate values from the provider of localization data. * * @param locale the locale to use, not null * @return the week-definition, not null */ public static WeekFields of(Locale locale) { Jdk8Methods.requireNonNull(locale, "locale"); locale = new Locale(locale.getLanguage(), locale.getCountry()); // elminate variants // obtain these from GregorianCalendar for now GregorianCalendar gcal = new GregorianCalendar(locale); int calDow = gcal.getFirstDayOfWeek(); DayOfWeek dow = DayOfWeek.SUNDAY.plus(calDow - 1); int minDays = gcal.getMinimalDaysInFirstWeek(); return WeekFields.of(dow, minDays); }
LocalDate now = LocalDate.now(); // determine country (Locale) specific first day of current week DayOfWeek firstDayOfWeek = WeekFields.of(Locale.getDefault()).getFirstDayOfWeek(); LocalDate startOfCurrentWeek = now.with(TemporalAdjusters.previousOrSame(firstDayOfWeek)); // determine last day of current week DayOfWeek lastDayOfWeek = firstDayOfWeek.plus(6); // or minus(1) LocalDate endOfWeek = now.with(TemporalAdjusters.nextOrSame(lastDayOfWeek)); // Print the dates of the current week LocalDate printDate = startOfCurrentWeek; DateTimeFormatter formatter = DateTimeFormatter.ofPattern("EEE dd/MM/yyyy"); for (int i=0; i < 7; i++) { System.out.println(printDate.format(formatter)); printDate = printDate.plusDays(1); }