Java Date Time - OffsetDateTime compareTo(OffsetDateTime other) example








OffsetDateTime compareTo(OffsetDateTime other) compares this OffsetDateTime to another date-time.

Syntax

compareTo has the following syntax.

public int compareTo(OffsetDateTime other)

Example

The following example shows how to use compareTo.

import java.time.OffsetDateTime;

public class Main {
  public static void main(String[] args) {
    OffsetDateTime o = OffsetDateTime.MAX;
    
    System.out.println(o.compareTo(OffsetDateTime.MIN));
  }
}

The code above generates the following result.