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.yiibai;
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