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



說明

java.time.Instant.plusSeconds(long secondsToAdd) 方法返回此瞬時副本,新增以秒為單位指定持續時間。

宣告

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

public Instant plusSeconds(long secondsToAdd)

引數

secondsToAdd − 要新增的秒數,正數或負數。

返回值

基於此瞬時,新增以指定秒為單位的瞬時,非空。

異常

  • DateTimeException − 如果結果超出了最大或最小瞬時。

  • ArithmeticException − 如果出現數字溢位。

示例

以下示例演示如何使用 java.time.Instant.plusSeconds(long secondsToAdd) 方法。

package com.tutorialspoint;

import java.time.Instant;

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

      Instant instant = Instant.parse("2017-02-03T10:37:30.00Z");
      Instant result = instant.plusSeconds(10);
      System.out.println(result);   
   }
}

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

2017-02-03T10:37:40Z
廣告
© . All rights reserved.