Instant range() method in Java with Examples Last Updated : 28 Nov, 2018 Comments Improve Suggest changes Like Article Like Report The range() method of Instant class helps to get the range of valid values for the field passes as a parameter. This method returns ValueRange object which contains the minimum and maximum valid values for a field. This instant is helpful to enhance the accuracy of the returned range. When the field is not supported and method is unable to return range values then an exception is thrown. Syntax: public ValueRange range(TemporalField field) Parameters: This method accepts one parameter field which is the field to get range of values. Returns: This method returns ValueRange which is the range of valid values for the field, not null. Exception: This method throws following exceptions: DateTimeException: if the range for the field cannot be obtained. UnsupportedTemporalTypeException: if the field is not supported. Below programs illustrate the range() method: Program 1: Java // Java program to demonstrate // Instant.range() method import java.time.*; import java.time.temporal.ChronoField; import java.time.temporal.ValueRange; public class GFG { public static void main(String[] args) { // create a Instant object Instant instant = Instant.parse("2018-10-28T19:34:50.63Z"); // print Instant System.out.println("Instant: " + instant); // get range of MILLI_OF_SECOND field // from instant using range method ValueRange range = instant.range(ChronoField.MILLI_OF_SECOND); // print range of MILLI_OF_SECOND System.out.println("Range of MILLI_OF_SECOND: " + range); } } Program 2: Java // Java program to demonstrate // Instant.range() method import java.time.*; import java.time.temporal.ChronoField; import java.time.temporal.ValueRange; public class GFG { public static void main(String[] args) { // create a Instant object Instant instant = Instant.parse("2018-10-28T19:34:50.63Z"); // print Instant System.out.println("Instant: " + instant); // get range of NANO_OF_SECOND field // from instant using range method ValueRange range = instant.range(ChronoField.NANO_OF_SECOND); // print range of NANO_OF_SECOND System.out.println("Range of NANO_OF_SECOND: " + range); } } Program 3: To get UnsupportedTemporalTypeException Java // Java program to demonstrate // Instant.range() method import java.time.*; import java.time.temporal.ChronoField; import java.time.temporal.ValueRange; public class GFG { public static void main(String[] args) { // create a Instant object Instant instant = Instant.parse("2018-10-28T19:34:50.63Z"); // try to find range of era using ChronoField try { ValueRange secondvalue = instant.range(ChronoField.ERA); } catch (Exception e) { // print exception System.out.println("Exception: " + e); } } } References: https://docs.oracle.com/javase/10/docs/api/java/time/Instant.html#range(java.time.temporal.TemporalField) Comment More infoAdvertise with us Next Article Instant range() method in Java with Examples A AmanSingh2210 Follow Improve Article Tags : Java Java-Functions Java-Instant Java-time package Practice Tags : Java Similar Reads Instant now() Method in Java with Examples In Instant class, there are two types of now() method depending upon the parameters passed to it. now() now() method of a Instant class used to obtain the current instant from the system UTC clock.This method will return instant based on system UTC clock. Syntax: public static Instant now() Paramete 2 min read Instant parse() method in Java with Examples The parse() method of Instant class help to get an instance of Instant from a string value passed as parameter. This string is an instant in the UTC time zone. It is parsed using DateTimeFormatter.ISO_INSTANT. Syntax: public static Instant parse(CharSequence text) Parameters: This method accepts one 1 min read Instant toString() method in Java with Examples The toString() method of Instant class returns string representation of this instant using ISO-8601 representation and format used is the same as DateTimeFormatter.ISO_INSTANT. Syntax: public String toString() Returns: This method returns an ISO-8601 representation of this instant, not null. Below p 1 min read Instant until() Method in Java with Examples until() method of an Instant class used to calculate the amount of time between two Instant objects using TemporalUnit. The start and end points are this and the specified instant passed as a parameter. The result will be negative if the end is before the start. The calculation returns a whole numbe 2 min read Instant minus() method in Java with Examples In Instant class, there are two types of minus() method depending upon the parameters passed to it. minus(long amountTosubtract, TemporalUnit unit) minus() method of a Instant class used to returns a copy of this instant with the specified amount of unit subtracted.If it is not possible to subtract 2 min read Instant query() Method in Java with Examples query() method of an Instant class used to query this instant using the specified query as parameter.The TemporalQuery object passed as parameter define the logic to be used to obtain the result from this instant. Syntax: public <R> R query(TemporalQuery<R> query) Parameters: This method 2 min read Instant plus() method in Java with Examples In Instant class, there are two types of plus() method depending upon the parameters passed to it. plus(long amountToAdd, TemporalUnit unit) plus() method of a Instant class used to return a copy of this instant with the specified amount of unit added.If it is not possible to add the amount, because 2 min read Instant with() Method in Java with Examples In Instant class, there are two types of with() method depending upon the parameters passed to it. with(TemporalAdjuster adjuster) with(TemporalAdjuster adjuster) method of the Instant class used to adjusted this instant using TemporalAdjuster and after adjustment returns the copy of adjusted instan 3 min read Instant plusNanos() method in Java with Examples The plusNanos() method of Instant class adds nanoseconds value passed as parameter to this instant and return the result as an instant object. This returned Instant is immutable. Syntax: public Instant plusNanos(long nanosToAdd) Parameters: This method accepts one parameter nanosToAdd which is nanos 2 min read Instant get() method in Java with Examples The get() method of Instant class helps to get the value for the specified field passed as parameter from this instant as an integer value. This method queries this instant for the value of the field and the returned value will always be within the valid range of values for the field. When the field 2 min read Like