java.time.OffsetTime.plus(long amountToAdd,TemporalUnit unit)
方法返回此時間的副本,並新增了指定的數量。
以下是java.time.OffsetTime.plus(long amountToAdd,TemporalUnit unit)
方法的宣告。
public OffsetTime plus(long amountToAdd, TemporalUnit unit)
amountToAdd
- 要新增到結果中的單位數量可能為負數。unit
- 要新增的金額的單位,而不是null
。基於此時間的OffsetTime
,新增了指定的數量,而不是null
。
DateTimeException
- 如果無法新增。UnsupportedTemporalTypeException
- 如果不支援該單位。ArithmeticException
- 如果發生數位溢位。以下範例顯示了java.time.OffsetTime.plus(long amountToAdd,TemporalUnit unit)
方法的用法。
package com.yiibai;
import java.time.OffsetTime;
import java.time.temporal.ChronoUnit;
public class OffsetTimeDemo {
public static void main(String[] args) {
OffsetTime time = OffsetTime.parse("10:15:30+01:00");
OffsetTime time1 = time.plus(10, ChronoUnit.HOURS);
System.out.println(time1);
}
}
編譯並執行上面的程式,這將產生以下結果 -
20:15:30+01:00