java.time.Instant.plus() 方法

描述

java.time.Instant.plus(TemporalAmount amountToAdd) 方法返回此瞬间的副本,其中添加了指定的数量。


声明

以下是 java.time.Instant.plus(TemporalAmount amountToAdd) 方法的声明。

public Instant plus(TemporalAmount amountToAdd)

参数

amountToAdd − 要添加的数量,而不是 null。


返回值

一个基于此瞬间的瞬间,添加了指定的数量,不为空。


异常

  • DateTimeException − 如果无法添加。

  • ArithmeticException − 如果发生数字溢出。


示例

下面的例子展示了 java.time.Instant.plus(TemporalAmount amountToAdd) 方法的使用。

package com.tutorialspoint;

import java.time.Instant;
import java.time.Duration;

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

      Instant instant = Instant.parse("2017-02-03T10:37:30.00Z");
      Duration duration = Duration.ofHours(5); 
      Instant result = instant.plus(duration);
      System.out.println(result);  
   }
}

让我们编译并运行上面的程序,这将产生下面的结果 −

2017-02-03T15:37:30Z