java.time.OffsetDateTime.query() Method Example



Description

The java.time.OffsetDateTime.query(TemporalQuery<R> query) method queries this date-time using the specified query.

Declaration

Following is the declaration for java.time.OffsetDateTime.query(TemporalQuery<R> query) method.

public <R> R query(TemporalQuery<R> query)

Parameters

query − the query to invoke, not null.

Return Value

the query result, null may be returned (defined by the query).

Exceptions

  • DateTimeException − if unable to query (defined by the query).

  • ArithmeticException − if numeric overflow occurs (defined by the query).

Example

The following example shows the usage of java.time.OffsetDateTime.query(TemporalQuery<R> query) method.

package com.tutorialspoint;

import java.time.OffsetDateTime;
import java.time.temporal.TemporalQueries;

public class OffsetDateTimeDemo {
   public static void main(String[] args) {

      OffsetDateTime date = OffsetDateTime.parse("2014-12-03T10:15:30+01:00");
      System.out.printf("OffsetDateTime precision is %s%n",
         date.query(TemporalQueries.precision()));
   }
}

Let us compile and run the above program, this will produce the following result −

OffsetDateTime precision is Nanos
Advertisements