java.time.OffsetTime.compareTo(OffsetTime other)
方法將此時間與另一時間進行比較。
聲明
以下是java.time.OffsetTime.compareTo(OffsetTime other)
方法的聲明。
public int compareTo(OffsetTime other)
參數
other
- 比較的另一個時間,而不是null
。
返回值
比較器值,如果小則返回為負值,如果大則返回為正。
異常
NullPointerException
- 另一個為null
。
示例
以下示例顯示了java.time.OffsetTime.compareTo(OffsetTime other)
方法的用法。
package com.zaixian;
import java.time.OffsetTime;
public class OffsetTimeDemo {
public static void main(String[] args) {
OffsetTime time = OffsetTime.parse("12:30:30+01:00");
System.out.println(time);
OffsetTime time1 = OffsetTime.parse("12:35:30+01:00");
System.out.println(time1);
System.out.println(time1.compareTo(time));
}
}
編譯並運行上面的程式,這將產生以下結果 -
12:30:30+01:00
12:35:30+01:00
1
上一篇:
java.time.OffsetTime類
下一篇:
java.time.Period類