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



說明

java.time.ZonedDateTime.with(TemporalField field, long newValue) 方法返回該日期時間的副本,其中指定的欄位設定為新值。

宣告

以下是 java.time.ZonedDateTime.with(TemporalField field, long newValue) 方法的宣告。

public ZonedDateTime with(TemporalField field, long newValue)

long with(TemporalField field, long newValue)

  • 引數

  • field - 要在結果中設定的欄位,不為 null。

newValue - 結果中欄位的新值。

返回值

基於此項進行調整的 ZonedDateTime,不為 null。

  • 異常

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

  • UnsupportedTemporalTypeException - 如果該欄位不受支援。

ArithmeticException - 如果出現數字溢位。

示例

package com.tutorialspoint;

import java.time.ZonedDateTime;
import java.time.temporal.ChronoField;

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(ChronoField.DAY_OF_MONTH,13);
      System.out.println(result);  
   }
}

實際演示

2017-03-13T12:25:38.492+05:30[Asia/Calcutta]
Print Page
© . All rights reserved.