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

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.zaixian;

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

上一篇: java.time.OffsetTime類 下一篇: java.time.Period類