java.time.OffsetTime.until(Temporal endExclusive,TemporalUnit unit)
方法根據指定的單位計算到另一個時間的時間量。
以下是java.time.OffsetTime.until(Temporal endExclusive,TemporalUnit unit)
方法的宣告。
public long until(Temporal endExclusive, TemporalUnit unit)
endDateExclusive
- 結束日期(包含),轉換為OffsetTime
,而不是null
。unit
- 衡量金額的單位,而不是null
。此時間與結束時間之間的時間量。
DateTimeException
- 如果無法計算金額,或者結束時間不能轉換為OffsetTime
。UnsupportedTemporalTypeException
- 如果不支援該單位。ArithmeticException
- 如果發生數位溢位。以下範例顯示了java.time.OffsetTime.until(Temporal endExclusive,TemporalUnit unit)
方法的用法。
package com.yiibai;
import java.time.OffsetTime;
import java.time.temporal.ChronoUnit;
public class OffsetTimeDemo {
public static void main(String[] args) {
OffsetTime time = OffsetTime.parse("10:15:30+01:00");
OffsetTime time1 = OffsetTime.now();
System.out.println(time.until(time1, ChronoUnit.HOURS));
}
}
編譯並執行上面的程式,這將產生以下結果 -
1