java.time.Instant.plusSeconds(long secondsToAdd)方法

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

聲明

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

public Instant plusSeconds(long secondsToAdd)

參數

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

返回值

基於此瞬間的Instant,添加了指定的秒數,而不是null

異常

  • DateTimeException - 如果結果超過最大或最小瞬間。
  • ArithmeticException - 如果發生數字溢出。

例子

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

package com.zaixian;

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

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