与 一起使用。getNano()
getEpochSeconds()
int getNano()
获取从秒开始沿时间线的纳秒数。纳秒秒值测量 从 返回的第二个纳秒的总数。getEpochSecond
使用 转换为所需的单位,如注释所示:TimeUnit
Instant inst = Instant.now();
// Nano seconds since epoch, may overflow
long nanos = TimeUnit.SECONDS.toNanos(inst.getEpochSecond()) + inst.getNano();
// Microseconds since epoch, may overflow
long micros = TimeUnit.SECONDS.toMicros(inst.getEpochSecond()) + TimeUnit.NANOSECONDS.toMicros(inst.getNano());
您还可以了解它们何时溢出:
// 2262-04-11T23:47:16.854775807Z
Instant.ofEpochSecond(TimeUnit.NANOSECONDS.toSeconds(Long.MAX_VALUE),
Long.MAX_VALUE % TimeUnit.SECONDS.toNanos(1));
// +294247-01-10T04:00:54.775807Z
Instant.ofEpochSecond(TimeUnit.MICROSECONDS.toSeconds(Long.MAX_VALUE),
TimeUnit.MICROSECONDS.toNanos(Long.MAX_VALUE % TimeUnit.SECONDS.toMicros(1)))