Ejemplo de método java.time.Instant.query ()

Descripción

los java.time.Instant.query(TemporalQuery query) El método consulta este instante utilizando la consulta especificada.

Declaración

A continuación se muestra la declaración de java.time.Instant.query(TemporalQuery query) método.

public 
      
        R query(TemporalQuery
       
         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.Instant.query(TemporalQuery query) method.

package com.tutorialspoint;

import java.time.Instant;
import java.time.temporal.TemporalQueries;

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

      Instant instant = Instant.parse("2014-12-03T10:15:30.00Z");
      System.out.printf("Instant precision is %s%n",
         instant.query(TemporalQueries.precision()));
   }
}

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

Instant precision is Nanos