OffsetDateTime query() method in Java with Examples Last Updated : 10 Jan, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report query() method of an OffsetDateTime class used to query this OffsetDateTime using the specified query as parameter.The TemporalQuery object passed as parameter define the logic to be used to obtain the result from this OffsetDateTime. Syntax: public <R> R query(TemporalQuery<R> query) Parameters: This method accepts only one parameter query which is the query to invoke. Return value: This method returns the query result, null may be returned. Exception:This method throws following Exceptions: DateTimeException - if unable to query . ArithmeticException - if numeric overflow occurs. Below programs illustrate the query() method: Program 1: Java // Java program to demonstrate // OffsetDateTime.query() method import java.time.*; import java.time.temporal.*; public class GFG { public static void main(String[] args) { // create OffsetDateTime object OffsetDateTime olt = OffsetDateTime.parse( "2018-12-12T13:30:30+05:00"); // apply query method of OffsetDateTime class String value = olt.query( TemporalQueries.precision()) .toString(); // print the result System.out.println("Precision value" + " for OffsetDateTime is " + value); } } Output: Precision value for OffsetDateTime is Nanos Program 2: Java // Java program to demonstrate // OffsetDateTime.query() method import java.time.*; import java.time.temporal.*; public class GFG { public static void main(String[] args) { // create OffsetDateTime object OffsetDateTime olt = OffsetDateTime.parse( "2018-12-12T13:30:30+05:00"); // apply query method of // OffsetDateTime class // print the result System.out.println("offset value " + "for OffsetDateTime is " + olt.query( TemporalQueries.offset())); } } Output: offset value for OffsetDateTime is +05:00 References: https://docs.oracle.com/javase/10/docs/api/java/time/OffsetDateTime.html#query(java.time.temporal.TemporalQuery) Comment More infoAdvertise with us Next Article OffsetDateTime query() method in Java with Examples A AmanSingh2210 Follow Improve Article Tags : Java Java-Functions Java-time package Java-OffsetDateTime Practice Tags : Java Similar Reads OffsetTime query() method in Java with examples The Query() method of OffsetTime class in Java queries this time using the specified query. Syntax : public R query(TemporalQuery query) Parameter: This method accepts a single parameter query that specifies the query to be invoked and not null. Return Value: It returns the query result, null may be 1 min read OffsetDateTime range() method in Java with Examples The range() method of the OffsetDateTime class used to get the ValueRange object which is the range of field in terms of the minimum and maximum values for the field passed as a parameter to this method. The method returns ValueRange object only for those fields which are supported by OffsetDateTime 2 min read OffsetDateTime until() Method in Java with Examples until() method of the OffsetDateTime class used to calculate the amount of time between two OffsetDateTime objects using TemporalUnit. The start and end points are this and the specified OffsetDateTime passed as a parameter. The result will be negative if the end is before the start. The calculation 2 min read OffsetDateTime plusYears() method in Java with examples The plusYears() method of OffsetDateTime class in Java returns a copy of this OffsetDateTime with the specified number of years added to the parsed date and time. Syntax: public OffsetDateTime plusYears(long years) Parameter: This method accepts a single parameter years which specifies the years to 2 min read OffsetDateTime of() method in Java with Examples The of(int year, int month, int day, int hour, int minute, int second, int nanosecond, ZoneOffset offset) method of the OffsetDateTime class in Java is used to create an instance of OffsetDateTime from the passed values of year, month, day, hour, minute, second, nanosecond and offset. In this method 3 min read Like