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



說明

java.time.ZonedDateTime.plusNanos(long nanoseconds) 方法返回添加了指定納秒的此日期時間的副本。

宣告

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

public ZonedDateTime plusNanos(long nanoseconds)

引數

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

返回值

一個 ZonedDateTime,基於此日期時間,添加了納秒,非空。

異常

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

示例

以下示例演示了 java.time.ZonedDateTime.plusNanos(long nanoseconds) 方法的使用。

package com.tutorialspoint;

import java.time.ZonedDateTime;

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

      ZonedDateTime date = ZonedDateTime.parse("2017-03-28T12:25:38.492+05:30[Asia/Calcutta]");
      System.out.println(date.plusNanos(20000));  
   }
}

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

2017-03-28T12:25:38.492020+05:30[Asia/Calcutta]
廣告