Java Date Time - YearMonth adjustInto(Temporal temporal) example








YearMonth adjustInto(Temporal temporal) adjusts the specified temporal object to have this year-month.

Syntax

adjustInto has the following syntax.

public Temporal adjustInto(Temporal temporal)

Example

The following example shows how to use adjustInto.

import java.time.Month;
import java.time.YearMonth;
import java.time.temporal.Temporal;
//  w w  w .  j av  a2 s .c o m
public class Main {
  public static void main(String[] args) {
    YearMonth y = YearMonth.now();
    Temporal s = y.adjustInto(YearMonth.of(1990, Month.JANUARY));
    System.out.println(s);

  }
}

The code above generates the following result.