Java Date Time - YearMonth from(TemporalAccessor temporal) example








YearMonth from(TemporalAccessor temporal) creates an instance of YearMonth from a temporal object.

Syntax

from has the following syntax.

public static YearMonth from(TemporalAccessor temporal)

Example

The following example shows how to use from.

import java.time.LocalDate;
import java.time.YearMonth;
//w  ww  . j  ava  2 s .  c om
public class Main {
  public static void main(String[] args) {
    YearMonth y = YearMonth.from(LocalDate.now());
    
    System.out.println(y);

  }
}

The code above generates the following result.