Java Date Time - ZoneOffset compareTo(ZoneOffset other) example








ZoneOffset compareTo(ZoneOffset other) compares this offset to another offset in descending order.

Syntax

compareTo has the following syntax.

public int compareTo(ZoneOffset other)

Example

The following example shows how to use compareTo.

import java.time.ZoneOffset;

public class Main {
  public static void main(String[] args) {
    ZoneOffset z = ZoneOffset.UTC;
    System.out.println(z.compareTo(ZoneOffset.UTC));
  }
}

The code above generates the following result.