java.time.LocalTime.with(TemporalAdjuster adjuster)方法

java.time.LocalTime.with(TemporalAdjuster adjuster)方法返回此次調整後的副本。

聲明

以下是java.time.LocalTime.with(TemporalAdjuster adjuster)方法的聲明。

public LocalTime with(TemporalAdjuster adjuster)

參數

  • adjuster - 要使用的調整器,不能為null

返回值

基於此LocalTime進行調整,不能為null

異常

  • DateTimeException - 如果無法進行調整。
  • ArithmeticException - 如果發生數字溢出。

示例

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

package com.zaixian;

import java.time.LocalTime;

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

      LocalTime date = LocalTime.parse("10:15:30");
      LocalTime result = date.with(LocalTime.NOON);
      System.out.println(result);
   }
}

編譯並運行上面的程式,這將產生以下結果 -

12:00

上一篇: java.time.LocalTime類 下一篇: java.time.MonthDay類