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



說明

java.time.ZonedDateTime.plusMonths(long monthsToAdd) 方法返回加上指定月份的此日期-時間的一個副本。

宣告

以下是 java.time.ZonedDateTime.plusMonths(long monthsToAdd) 方法的宣告。

public ZonedDateTime plusMonths(long monthsToAdd)

引數

monthsToAdd − 要新增的月份,可以為負數。

返回值

基於此日期-時間並添加了月份的 ZonedDateTime,不為 null。

異常

DateTimeException − 如果結果超出受支援的日期範圍。

示例

以下示例顯示了 java.time.ZonedDateTime.plusMonths(long monthsToAdd) 方法的用法。

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.plusMonths(2));  
   }
}

讓我們編譯並執行上述程式,這將產生以下結果 −

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