java.time.YearMonth.get(TemporalField field)
方法獲取所請求字段的值。
聲明
以下是java.time.YearMonth.get(TemporalField field)
方法的聲明。
public long get(TemporalField field)
參數
field
- 要為其返回值的TemporalField
。
返回值
單位的long
值。
異常
DateTimeException
- 如果不支持該單元。UnsupportedTemporalTypeException
- 如果不支持該單位。ArithmeticException
- 如果發生數字溢出。
示例
以下示例顯示了java.time.YearMonth.get(TemporalField field)
方法的用法。
package com.zaixian;
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
上一篇:
java.time.YearMonth類
下一篇:
java.time.ZonedDateTime類