java.time.Duration.plusSeconds()方法

java.time.Duration.plusSeconds(long secondsToAdd)方法返回此持續時間的副本,並添加指定的持續時間(以秒為單位)。

聲明

以下是java.time.Duration.plusSeconds(long secondsToAdd)方法的聲明。

public Duration plusSeconds(long secondsToAdd)

參數

  • secondsToAdd - 添加的秒數,正數或負數。

返回值

持續時間基於此持續時間並添加指定的秒數,而不是null

返回值

  • ArithmeticException - 如果發生數字溢出。

示例

以下示例顯示了java.time.Duration.plusSeconds(long secondsToAdd)方法的用法。

package com.zaixian;

import java.time.Duration;

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

      Duration duration = Duration.ofSeconds(2);
      Duration duration1 = duration.plusSeconds(1);
      System.out.println(duration1.toMillis());
   }
}

編譯並運行上面的程式,這將產生以下結果 -

3000

上一篇: java.time.Duration類 下一篇: java.time.Instant類