Java Date Time - LocalTime compareTo(LocalTime other) example








LocalTime compareTo(LocalTime other) compares this LocalTime to another time.

Syntax

compareTo has the following syntax.

public int compareTo(LocalTime other)

Example

The following example shows how to use compareTo.

import java.time.LocalTime;

public class Main {
  public static void main(String[] args) {
    LocalTime l = LocalTime.now();

    System.out.println(l.compareTo(LocalTime.NOON));
  }
}

The code above generates the following result.