java.time.ZonedDateTime.plus() 方法示例



描述

java.time.ZonedDateTime.plus(TemporalAmount amountToAdd) 方法返回一个时间日期副本,添加了指定数量。

声明

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

public ZonedDateTime plus(TemporalAmount amountToAdd)

参数

amountToAdd − 要添加的数量,不能为空。

返回值

基于当前日期和时间,在此基础上添加指定数量的 ZonedDateTime,不能为空。

异常

  • DateTimeException − 如果无法添加。

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

示例

以下示例展示了 java.time.ZonedDateTime.plus(TemporalAmount amountToAdd) 方法的用法。

package com.tutorialspoint;

import java.time.ZonedDateTime;
import java.time.Period;

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

      ZonedDateTime date = ZonedDateTime.parse("2017-03-28T12:25:38.492+05:30[Asia/Calcutta]");
      ZonedDateTime date1 = date.plus(Period.ofDays(10));
      System.out.println(date1);  
   }
}

让我们编译并运行以上程序,它将产生以下结果 −

2017-04-07T12:25:38.492+05:30[Asia/Calcutta]
广告
© . All rights reserved.