Java LocalDate set to next sixth Sunday

Description

Java LocalDate set to next sixth Sunday

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.Month;
import java.time.temporal.TemporalAdjusters;

public class Main {
  public static void main(String[] args) {
    LocalDate ld1 = LocalDate.of(2020, Month.MAY, 22);
    LocalDate ld2 = ld1.with(TemporalAdjusters.dayOfWeekInMonth(6,
        DayOfWeek.SUNDAY));/*ww  w  .j av  a  2  s.c  o  m*/
    System.out.println(ld1);
    System.out.println(ld2);

  }
}



PreviousNext

Related