java.time.Instant.plus(long amountToAdd,TemporalUnit unit)
方法返回此瞬間的副本,並添加了指定的數量。
聲明
以下是java.time.Instant.plus(long amountToAdd,TemporalUnit unit)
方法的聲明。
public Instant plus(long amountToAdd, TemporalUnit unit)
參數
amountToAdd
- 從結果中添加的單位數量可能為負數。unit
- 要添加的金額的單位,而不是null
。
返回值
基於此瞬間的Instant
,添加了指定的金額,而不是null
。
異常
DateTimeException
- 如果無法添加。UnsupportedTemporalTypeException
- 如果不支持該單位。ArithmeticException
- 如果發生數字溢出。
例子
以下示例顯示了java.time.Instant.plus(long amountToAdd,TemporalUnit unit)
方法的用法。
package com.zaixian;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
public class InstantDemo {
public static void main(String[] args) {
Instant instant = Instant.parse("2017-02-03T10:37:30.00Z");
Instant result = instant.plus(10, ChronoUnit.MINUTES);
System.out.println(result);
}
}
編譯並運行上面的程式,這將產生以下結果 -
2017-02-03T10:47:30Z
上一篇:
java.time.Instant類
下一篇:
java.time.LocalDate類