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



描述

java.time.Instant.with(TemporalAdjuster adjuster) 方法返回經過調整的此時間的副本。

宣告

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

public Instant with(TemporalAdjuster adjuster)

引數

adjuster - 要使用的調整器,不能為空。

返回值

根據此時間和所做調整生成的 Instant,不能為空。

異常

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

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

示例

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

package com.tutorialspoint;

import java.time.Instant;

public class InstantDemo {
   public static void main(String[] args) {

      Instant instant = Instant.parse("2017-12-03T10:15:30.00Z");
      Instant instant1 = Instant.now();
      Instant result = instant.with(instant1);
      System.out.println(result);
   }
}

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

2017-03-15T11:06:19.656Z
廣告
© . All rights reserved.