java.time.ZonedDateTime.plusWeeks() 方法

描述

java.time.ZonedDateTime.plusWeeks(long weekToAdd) 方法返回此日期时间的副本,其中添加了指定的周数。


声明

以下是 java.time.ZonedDateTime.plusWeeks(long weeksToAdd) 方法的声明。

public ZonedDateTime plusWeeks(long weeksToAdd)

参数

weeksToAdd − 要添加的周数可能为负数。


返回值

基于此日期时间的 ZonedDateTime 加上周数,不为空。


异常

DateTimeException − 如果结果超出支持的日期范围。


示例

下面的例子展示了 java.time.ZonedDateTime.plusWeeks(long weeksToAdd) 方法的使用。

package com.tutorialspoint;

import java.time.ZonedDateTime;

public class ZonedDateTimeDemo {
   public static void main(String[] args) {
 
      ZonedDateTime date = ZonedDateTime.parse("2017-03-28T12:25:38.492+05:30[Asia/Calcutta]");
      System.out.println(date.plusWeeks(2));  
   }
}

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

2017-04-11T12:25:38.492+05:30[Asia/Calcutta]