java.time.Duration.plusSeconds() 方法示例



說明

java.time.Duration.plusSeconds(long secondsToAdd) 方法返回一個此持續時間與秒為單位的指定持續時間相加的副本。

宣告

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

public Duration plusSeconds(long secondsToAdd)

public Duration plusSeconds(long secondsToAdd)

引數

secondsToAdd − 要新增的秒數,可以為正值或負值。

返回值

基於此持續時間的持續時間,新增的為指定的秒數,非 null。

異常

ArithmeticException − 如果發生數值溢位。

示例

package com.tutorialspoint;

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
列印頁面
廣告
© . All rights reserved.