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.zaixian;
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
上一篇:
java.time.OffsetTime類
下一篇:
java.time.Period類