java.time.OffsetTime.plus(TemporalAmount amountToAdd)方法

2019-10-16 22:40:34

java.time.OffsetTime.plus(TemporalAmount amountToAdd)方法返回此時間的副本,並新增了指定的數量。

宣告

以下是java.time.OffsetTime.plus(TemporalAmount amountToAdd)方法的宣告。

public OffsetTime plus(TemporalAmount amountToAdd)

引數

  • amountToAdd - 要新增的數量,而不是null

返回值

基於此時間的OffsetTime,新增了指定的數量,而不是null

異常

  • DateTimeException - 如果無法新增。
  • ArithmeticException - 如果發生數位溢位。

範例

以下範例顯示了java.time.OffsetTime.plus(TemporalAmount amountToAdd)方法的用法。

package com.yiibai;

import java.time.Duration;
import java.time.OffsetTime;

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

      OffsetTime time = OffsetTime.parse("10:15:30+01:00");
      OffsetTime time1 = time.plus(Duration.ofHours(10));
      System.out.println(time1);  
   }
}

編譯並執行上面的程式,這將產生以下結果 -

20:15:30+01:00