java.time.ZonedDateTime.withMonth 方法的示例



描述

java.time.ZonedDateTime.withMonth(int month) 方法會返回本 ZonedDateTime 的副本,其中月份已更改。

宣告

以下是對 java.time.ZonedDateTime.withMonth(int month) 方法的宣告。

public ZonedDateTime withMonth(int month)

```java

引數

month - 在結果中要設定的月份,從 1(1 月)到 12(12 月)。

返回值

一個基於本日期以及所請求月份的 ZonedDateTime,不為 null。

異常

DateTimeException - 如果月份的值無效。

示例

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]");
      ZonedDateTime result = date.withMonth(3);
      System.out.println(result);  
   }
}

即時演示

2017-03-28T12:25:38.492+05:30[Asia/Calcutta]
列印頁面