java.time.OffsetTime.compareTo() 方法
描述
java.time.OffsetTime.compareTo(OffsetTime other) 方法将此时间与另一个时间进行比较。
声明
以下是 java.time.OffsetTime.compareTo(OffsetTime other) 方法的声明。
public int compareTo(OffsetTime other)
参数
other − 另一个比较的时间,不为空。
返回值
比较器值,小于为负,大于为正。
异常
NullPointerException − 另一个为空。
示例
下面的例子展示了 java.time.OffsetTime.compareTo(OffsetTime other) 方法的使用。
package com.tutorialspoint;
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

