java.time.LocalTime.adjustInto() 方法示例



描述

java.time.LocalTime.adjustInto(Temporal temporal) 方法可調整指定的時間物件,使其與當前物件具有相同的時間。

宣告

以下是 java.time.LocalTime.adjustInto(Temporal temporal) 方法的宣告。

public Temporal adjustInto(Temporal temporal)

引數

temporal - 要調整的目標物件,不能為空。

返回值

調整後的物件,不能為空。

異常

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

  • ArithmeticException - 如果出現數值溢位。

示例

以下示例演示了 java.time.LocalTime.adjustInto(Temporal temporal) 方法的用法。

package com.tutorialspoint;

import java.time.LocalTime;
import java.time.ZonedDateTime;

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

      ZonedDateTime date = ZonedDateTime.now();
      System.out.println(date);  

      LocalTime date1 = LocalTime.parse("12:30:30");
      date = (ZonedDateTime)date1.adjustInto(date);
      System.out.println(date);  
   }
}

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

2017-03-20T11:52:58.297+05:30[Asia/Calcutta]
2017-03-20T12:30:30+05:30[Asia/Calcutta]
廣告
© . All rights reserved.