java.time.Instant.get() 方法示例



描述

java.time.Instant.get(TemporalField field)方法從此即時作為 int 獲取指定欄位的值。

宣告

以下是 java.time.Instant.get(TemporalField field) 方法的宣告。

public int get(TemporalField field)

引數

field - 要獲取的欄位,不能為空。

返回值

該欄位的值。

異常

  • DateTimeException - 如果無法獲得欄位的值,或該值超出該欄位的有效值範圍。

  • UnsupportedTemporalTypeException - 如果不支援該欄位或值範圍超出 int。

  • ArithmeticException - 如果發生數值溢位。

示例

以下示例演示了 java.time.Instant.get(TemporalField field) 方法的使用。

package com.tutorialspoint;

import java.time.Instant;
import java.time.temporal.ChronoField;

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

      Instant instant = Instant.parse("2017-03-03T10:37:30.00Z");
      System.out.println(instant.get(ChronoField.NANO_OF_SECOND));
   }
}

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

0
廣告
© . All rights reserved.