java.time.OffsetTime.plusNanos() 方法示例



說明

java.time.OffsetTime.plusNanos(long nanoseconds) 方法將返回一個在此時間基礎上,且新增指定納秒數的副本。

申明

以下是 java.time.OffsetTime.plusNanos(long nanoseconds) 方法的宣告。

public OffsetTime plusNanos(long nanoseconds)

引數

nanoseconds − 要新增的納秒數,可以是負數。

返回值

一個在此時間基礎上且已新增納秒數的 OffsetTime,且不為 null。

異常情況

DateTimeException − 如果結果超出支援的日期範圍。

示例

以下示例展示了 java.time.OffsetTime.plusNanos(long nanoseconds) 方法的用法。

package com.tutorialspoint;

import java.time.OffsetTime;

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

      OffsetTime date = OffsetTime.parse("10:15:30+01:00");
      System.out.println(date.plusNanos(20000));  
   }
}

讓我們編譯並執行以上程式,這將產生以下結果 −

10:15:30.000020+01:00
廣告
© . All rights reserved.