Java Date Time - YearMonth isSupported(TemporalUnit unit) example








YearMonth isSupported(TemporalUnit unit) checks if the specified unit is supported.

Syntax

isSupported has the following syntax.

public boolean isSupported(TemporalUnit unit)

Example

The following example shows how to use isSupported.

import java.time.YearMonth;
import java.time.temporal.ChronoUnit;
//from   w  w  w.  ja  va 2s .c om
public class Main {
  public static void main(String[] args) {
    YearMonth y = YearMonth.now();
    boolean m = y.isSupported(ChronoUnit.YEARS);
    System.out.println(m);

  }
}

The code above generates the following result.