long getLong(TemporalField field)
描述 (Description)
java.time.YearMonth.getLong(TemporalField field)方法java.time.YearMonth.getLong(TemporalField field)获取指定字段的值为long。
声明 (Declaration)
以下是java.time.YearMonth.getLong(TemporalField field)方法的声明。
public long getLong(TemporalField field)
参数 (Parameters)
field - 要获取的字段,而不是null。
返回值 (Return Value)
该字段的值。
异常 (Exceptions)
DateTimeException - 如果无法获取该字段的值或该值超出该字段的有效值范围。
UnsupportedTemporalTypeException - 如果不支持该字段或值的范围超过long。
ArithmeticException - 如果发生数字溢出
例子 (Example)
以下示例显示了java.time.YearMonth.getLong(TemporalField field)方法的用法。
package com.iowiki;
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.getLong(ChronoField.YEAR_OF_ERA));
}
}
让我们编译并运行上面的程序,这将产生以下结果 -
2017