Java Date Time - DayOfWeek adjustInto(Temporal temporal) example








DayOfWeek adjustInto(Temporal temporal) adjusts the specified temporal object to have this day-of-week.

This method returns a temporal object of the same observable type as the input with the day-of-week changed.

Syntax

adjustInto has the following syntax.

public Temporal adjustInto(Temporal temporal)

Example

The following example shows how to use adjustInto.

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.Month;
import java.time.temporal.Temporal;
//from  ww  w  .ja  v a2 s  . c  o m
public class Main {
  public static void main(String[] args) {
    LocalDate localDate = LocalDate.of(2014, Month.JUNE, 21);
    DayOfWeek dayOfWeek = DayOfWeek.from(localDate);
    
    Temporal i = dayOfWeek.adjustInto(LocalDate.of(2014, Month.MAY, 22));
    System.out.println(i);

    
  }
}

The code above generates the following result.