The query(TemporalQuery) method of ZoneOffset Class in java.time package is used to execute a query this ZoneOffset using the TemporalQuery passed as the parameter. This method returns the query result in the form of specified type.
Syntax:
public <R> R query(TemporalQuery<R> temporalQuery)
Parameters: This method accepts a parameter TemporalQuery which is the query to be executed upon on this ZoneOffset.
Return Value: This method returns a R type query result of the specified query.
Exceptions: This method throws:
- DateTimeException: if unable to query (defined by the query).
- ArithmeticException: if numeric overflow occurs (defined by the query).
Below examples illustrate the ZoneOffset.query() method:
Example 1:
// Java code to illustrate query() method import java.time.*; import java.time.temporal.*; public class GFG { public static void main(String[] args) { // Get the ZoneOffset instance ZoneOffset zoneOffset = ZoneOffset.of("+05:30"); System.out.println("ZoneOffset: " + zoneOffset); // Using query() method System.out.println("Offset value: " + zoneOffset.query(TemporalQueries.offset())); } } |
ZoneOffset: +05:30 Offset value: +05:30
Example 2:
// Java code to illustrate query() method import java.time.*; import java.time.temporal.*; public class GFG { public static void main(String[] args) { // Get the ZoneOffset instance ZoneOffset zoneOffset = ZoneOffset.of("Z"); System.out.println("ZoneOffset: " + zoneOffset); // Using query() method System.out.println("Zone value: " + zoneOffset.query(TemporalQueries.zone())); } } |
ZoneOffset: Z Zone value: Z
Reference: Oracle Doc
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
Recommended Posts:
- ZoneOffset compareTo(ZoneOffset) method in Java with Examples
- ZoneOffset of(String) method in Java with Examples
- ZoneOffset ofHours(int) method in Java with Examples
- ZoneOffset adjustInto(Temporal) method in Java with Examples
- ZoneOffset ofHoursMinutes(int, int) method in Java with Examples
- ZoneOffset from(TemporalAccessor) method in Java with Examples
- ZoneOffset ofHoursMinutesSeconds(int, int, int) method in Java with Examples
- ZoneOffset ofTotalSeconds(int) method in Java with Examples
- ZoneOffset getTotalSeconds() method in Java with Examples
- ZoneOffset getId() method in Java with Examples
- ZoneOffset toString() method in Java with Examples
- ZoneOffset hashCode() method in Java with Examples
- ZoneOffset systemDefault() method in Java with Examples
- ZoneOffset ofOffset() method in Java with Examples
- ZoneOffset normalized() method in Java with Examples
- ZoneOffset getDisplayName() method in Java with Examples
- ZoneOffset getAvailableZoneIds() method in Java with Examples
- ZoneOffset range(TemporalField) method in Java with Examples
- ZoneOffset isSupported(TemporalField) method in Java with Examples
- ZoneOffset getRules() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

