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



說明

java.time.Year.getLong(TemporalField field) 方法從今年作為 long 獲取指定欄位的值。

宣告

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

public long getLong(TemporalField field)

引數

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

返回值

該欄位的值。

異常

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

  • UnsupportedTemporalTypeException − 如果不支援該欄位或值範圍超出了 long。

  • ArithmeticException − 如果發生數字溢位

示例

以下示例展示了 java.time.Year.getLong(TemporalField field) 方法的用法。

package com.tutorialspoint;

import java.time.Year;
import java.time.temporal.ChronoField;

public class YearDemo {
   public static void main(String[] args) {
 
      Year date = Year.of(2017);
      System.out.println(date.getLong(ChronoField.YEAR_OF_ERA));  
   }
}

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

2017
廣告
© . All rights reserved.