- java.time 包類
- java.time - 首頁
- java.time - 時鐘
- java.time - 持續時間
- java.time - 瞬時
- java.time - 本地日期
- java.time - 本地日期時間
- java.time - 本地時間
- java.time - 月份日
- java.time - 偏移日期時間
- java.time - 偏移時間
- java.time - 期間
- java.time - 年
- java.time - 年月
- java.time - 區域日期時間
- java.time - 時區 ID
- java.time - 時區偏移
- java.time 包列舉
- java.time - 月
- java.time 有用資源
- java.time - 討論
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
廣告