當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Java 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

相關用法


注:本文由純淨天空篩選整理自 java.time.Instant.with() Method Example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。