Sunday, February 8, 2026
HomeLanguagesJavaChronoField range() method in Java with Examples

ChronoField range() method in Java with Examples

The range() method of ChronoField enum is used to return the range of valid values for the ChronoField constant.All fields of this range can be expressed as a long integer.

Syntax:

public ValueRange range()

Parameters: This method accepts nothing.

Return value: This method returns the range of valid values for the field, not null.

Below programs illustrate the ChronoField.range() method:
Program 1:




// Java program to demonstrate
// ChronoField.range() method
  
import java.time.temporal.*;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // get chronoField
        ChronoField chronoField
            = ChronoField.valueOf("HOUR_OF_DAY");
  
        // apply range()
        ValueRange rangeAttribute
            = chronoField.range();
  
        // print
        System.out.println("ValueRange for HOUR_OF_DAY"
                           + " is :"
                           + rangeAttribute);
    }
}


Output:

ValueRange for HOUR_OF_DAY is :0 - 23

Program 2:




// Java program to demonstrate
// ChronoField.range() method
  
import java.time.temporal.*;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // get chronoField
        ChronoField chronoField
            = ChronoField.valueOf("YEAR_OF_ERA");
  
        // apply range()
        ValueRange rangeAttribute
            = chronoField.range();
  
        // print
        System.out.println("ValueRange for YEAR_OF_ERA"
                           + " is:"
                           + rangeAttribute);
    }
}


Output:

ValueRange for YEAR_OF_ERA is:1 - 999999999/1000000000

References: https://docs.oracle.com/javase/10/docs/api/java/time/temporal/ChronoField.html#range()

RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32493 POSTS0 COMMENTS
Milvus
126 POSTS0 COMMENTS
Nango Kala
6864 POSTS0 COMMENTS
Nicole Veronica
11990 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12084 POSTS0 COMMENTS
Shaida Kate Naidoo
7000 POSTS0 COMMENTS
Ted Musemwa
7241 POSTS0 COMMENTS
Thapelo Manthata
6951 POSTS0 COMMENTS
Umr Jansen
6936 POSTS0 COMMENTS