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(TemporalQueryquery) 方法。

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

讓我們編譯並執行以上程式,它將產生以下結果 -

Instant precision is Nanos
廣告
© . All rights reserved.