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]
打印页面
© . All rights reserved.