Java - Adjust date to the sixth Sunday in May 2012.

Introduction

The date adjuster returns the June 10, 2012 because May 2012 does not have a sixth Sunday.

Demo

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(2012, Month.MAY, 22);
    LocalDate ld2 = ld1.with(TemporalAdjusters.dayOfWeekInMonth(6,
        DayOfWeek.SUNDAY));//from ww w  .  jav a2  s.c  o m
    System.out.println(ld1);
    System.out.println(ld2);

  }
}

Result

Related Topic