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



描述

java.time.ZonedDateTime.plusWeeks(long weeksToAdd) 方法返回添加指定周数后当前日期时间副本。

声明

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

public ZonedDateTime plusWeeks(long weeksToAdd)

参数

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

返回值

添加周数后的 {@code ZonedDateTime},不为 null。

异常

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]
广告
© . All rights reserved.