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



描述

java.time.ZonedDateTime.with(TemporalAdjuster adjuster) 方法返回此日期時間的已調整副本。

宣告

以下是 java.time.ZonedDateTime.with(TemporalAdjuster adjuster) 方法的宣告。

public ZonedDateTime with(TemporalAdjuster adjuster)

引數

adjuster - 要使用的調整器,非空。

返回值

基於此日期時間並進行調整的 ZonedDateTime,非空。

異常

  • DateTimeException - 如果無法進行調整。

  • ArithmeticException - 如果發生數字溢位。

示例

以下示例演示了 java.time.ZonedDateTime.with(TemporalAdjuster adjuster) 方法的使用。

package com.tutorialspoint;

import java.time.ZonedDateTime;
import java.time.Month;
import java.time.temporal.TemporalAdjusters;

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.with(Month.JULY).with(TemporalAdjusters.lastDayOfMonth());
      System.out.println(result);  
   }
}

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

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