Java Date Time - ZonedDateTime equals(Object obj) example








ZonedDateTime equals(Object obj) checks if this date-time is equal to another date-time.

Syntax

equals has the following syntax.

public boolean equals(Object obj)

Example

The following example shows how to use equals.

import java.time.ZonedDateTime;

public class Main {
  public static void main(String[] args) {
    ZonedDateTime dateTime = ZonedDateTime.now();
    
    System.out.println(dateTime.equals(ZonedDateTime.now()));
  } 
}

The code above generates the following result.