Javatime-instant-query

提供:Dev Guides
移動先:案内検索

java.time.Instant.query()メソッドの例

説明

  • java.time.Instant.query(TemporalQuery query)*メソッドは、指定されたクエリを使用してこのインスタントをクエリします。

宣言

以下は、* java.time.Instant.query(TemporalQuery query)*メソッドの宣言です。

public  R query(TemporalQuery query)

パラメーター

*query* -呼び出すクエリ、nullではない。

戻り値

クエリ結果、nullが返される場合があります(クエリによって定義されます)。

例外

  • DateTimeException -クエリできない場合(クエリで定義)。
  • ArithmeticException -数値オーバーフローが発生した場合(クエリで定義)。

次の例は、java.time.Instant.query(TemporalQuery query)メソッドの使用方法を示しています。

package com.finddevguides;

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()));
   }
}

上記のプログラムをコンパイルして実行すると、次の結果が生成されます-

Instant precision is Nanos