Exemple de méthode java.time.Instant.query ()

La description

le java.time.Instant.query(TemporalQuery query) la méthode interroge cet instant à l'aide de la requête spécifiée.

Déclaration

Voici la déclaration pour java.time.Instant.query(TemporalQuery query) méthode.

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