long getLong(TemporalField field)
描述 (Description)
java.time.OffsetDateTime.getLong(TemporalField field)方法从此日期时间获取指定字段的值为long。
声明 (Declaration)
以下是java.time.OffsetDateTime.getLong(TemporalField field)方法的声明。
public long getLong(TemporalField field)
参数 (Parameters)
field - 要获取的字段,而不是null。
返回值 (Return Value)
该字段的值。
异常 (Exceptions)
DateTimeException - 如果无法获取该字段的值或该值超出该字段的有效值范围。
UnsupportedTemporalTypeException - 如果不支持该字段或值的范围超过long。
ArithmeticException - 如果发生数字溢出
例子 (Example)
以下示例显示了java.time.OffsetDateTime.getLong(TemporalField field)方法的用法。
package com.iowiki;
import java.time.OffsetDateTime;
import java.time.temporal.ChronoField;
public class OffsetDateTimeDemo {
public static void main(String[] args) {
OffsetDateTime date = OffsetDateTime.parse("2017-02-03T12:30:30+01:00");
System.out.println(date.getLong(ChronoField.CLOCK_HOUR_OF_DAY));
}
}
让我们编译并运行上面的程序,这将产生以下结果 -
12