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



描述

java.time.Instant.getLong(TemporalField field) 方法從瞬間獲取指定欄位的值,以 long 形式獲取。

宣告

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

public long getLong(TemporalField field)

引數

field - 要獲取的欄位,非空。

返回值

欄位的值。

異常

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

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

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

示例

以下示例演示了 java.time.Instant.getLong(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.getLong(ChronoField.NANO_OF_SECOND));
   }
}

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

0
廣告
© . All rights reserved.