Java Instant query() method
Last Updated : 17 Mar 2025
The query() method of Java Instant class is used to query the instant using the specified query. This method uses the specified query strategy object. The TemporalQuery object defines the logic to be used to obtain the result.
Syntax
Parameters
R - As we can see in the syntax, there is R which is denoted as a type parameter which specifies the type of the result.
query - It specifies the query to invoke. Parameters cannot be null.
Returns
It returns the query result. It may be returned Null value which is defined by the query.
Exception
DateTimeException - If unable to query (defined by the query)
ArithmeticException - If numeric overflow occurs (defined by the query)
Example 1
Output:
Example 2
Output:
2017-05-01T20:57:09.883Z Nanos
Example 3
Output: