java.time.LocalTime.query() Method Example



Description

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

Declaration

Following is the declaration for java.time.LocalTime.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.LocalTime.query(TemporalQuery<R> query) method.

package com.tutorialspoint;

import java.time.LocalTime;
import java.time.temporal.TemporalQueries;

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

      LocalTime date = LocalTime.parse("10:15:30");
      System.out.printf("LocalTime precision is %s%n",
         date.query(TemporalQueries.precision()));
   }
}

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

LocalTime precision is Nanos
Advertisements