Java Date Time - YearMonth range(TemporalField field) example








YearMonth range(TemporalField field) gets the range of valid values for the specified field.

Syntax

range has the following syntax.

public ValueRange range(TemporalField field)

Example

The following example shows how to use range.

import java.time.YearMonth;
import java.time.temporal.ChronoField;
import java.time.temporal.ValueRange;
/*from   w ww.j a  v  a2  s  .  c om*/
public class Main {
  public static void main(String[] args) {
    YearMonth y = YearMonth.now();
    ValueRange m = y.range(ChronoField.YEAR);
    System.out.println(m);

  }
}

The code above generates the following result.