目录

int compareTo(LocalTime other)

描述 (Description)

java.time.LocalTime.compareTo(LocalTime other)方法将此时间与另一时间进行比较。

声明 (Declaration)

以下是java.time.LocalTime.compareTo(LocalTime other)方法的声明。

public int compareTo(LocalTime other)

参数 (Parameters)

other - 比较的另一个时间,而不是null。

返回值 (Return Value)

比较器值,如果更小则为负,如果更大则为正。

异常 (Exceptions)

NullPointerException - 另一个为null。

例子 (Example)

以下示例显示了java.time.LocalTime.compareTo(LocalTime other)方法的用法。

package com.iowiki;
import java.time.LocalTime;
public class LocalTimeDemo {
   public static void main(String[] args) {
      LocalTime time = LocalTime.parse("12:30:30");
      System.out.println(time);  
      LocalTime time1 = LocalTime.parse("12:35:30");
      System.out.println(time1);  
      System.out.println(time1.compareTo(time));  
   }
}

让我们编译并运行上面的程序,这将产生以下结果 -

12:30:30
12:35:30
1
↑回到顶部↑
WIKI教程 @2018