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类