當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Java java.time.Instant.query()用法及代碼示例


描述

這個java.time.Instant.query(TemporalQuery query)方法使用指定的查詢查詢這一瞬間。

聲明

以下是聲明java.time.Instant.query(TemporalQuery query)方法。

public  R query(TemporalQuery query)

參數

query- 要調用的查詢,不為空。

返回值

查詢結果,可能返回null(由查詢定義)。

異常

  • DateTimeException- 如果無法查詢(由查詢定義)。

  • ArithmeticException- 如果發生數字溢出(由查詢定義)。

示例

下麵的例子展示了 java.time.Instant.query(TemporalQuery) 的用法查詢)方法。

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

相關用法


注:本文由純淨天空篩選整理自 java.time.Instant.query() Method Example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。