当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java java.time.Instant.getLong()用法及代码示例



描述

这个java.time.Instant.getLong(TemporalField field)方法从这一刻开始获取指定字段的值。

声明

以下是声明java.time.Instant.getLong(TemporalField field)方法。

public long getLong(TemporalField field)

参数

field- 要获取的字段,不为空。

返回值

字段的值。

异常

  • DateTimeException- 如果无法获取字段的值或该值超出该字段的有效值范围。

  • UnsupportedTemporalTypeException- 如果该字段不受支持或值范围超过 int。

  • ArithmeticException- 如果发生数字溢出。

示例

下面的例子展示了 java.time.Instant.getLong(TemporalField field) 方法的用法。

package com.tutorialspoint;

import java.time.Instant;
import java.time.temporal.ChronoField;

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

      Instant instant = Instant.parse("2017-03-03T10:37:30.00Z");
      System.out.println(instant.getLong(ChronoField.NANO_OF_SECOND));
   }
}

让我们编译并运行上面的程序,这将产生以下结果 -

0

相关用法


注:本文由纯净天空筛选整理自 java.time.Instant.getLong() Method Example。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。