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



說明

java.time.YearMonth.get(TemporalField field) 方法獲取請求欄位的值。

宣告

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

public long get(TemporalField field)

引數

field − 要返回其值的 TemporalField。

返回值

單位的長整型值。

異常

  • DateTimeException − 如果不支援該單位。

  • UnsupportedTemporalTypeException − 如果不支援該單位。

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

示例

以下示例顯示了 java.time.YearMonth.get(TemporalField field) 方法的用法。

package com.tutorialspoint;

import java.time.YearMonth;
import java.time.temporal.ChronoField;

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

      YearMonth date = YearMonth.of(2017,12);
      System.out.println(date.get(ChronoField.YEAR_OF_ERA));
   }
}

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

2017
廣告
© . All rights reserved.