Thursday, October 23, 2025
HomeLanguagesJavaOffsetTime isEqual() method in Java with examples

OffsetTime isEqual() method in Java with examples

The isEqual() method of OffsetTime class in Java formats checks if the passed time is equal to the specified time in the parameter.

Syntax:

public boolean isEqual(OffsetTime other)

Parameter: This method accepts a single mandatory parameter other which specifies the time to be compared with.

Return Value: It returns true if the date is equal to the passed date, else it return false.

Below programs illustrate the isEqual() method:

Program 1 :




// Java program to demonstrate the isEqual() method
import java.time.OffsetTime;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // Parses the time
        OffsetTime time1
            = OffsetTime.parse("15:30:30+07:00");
  
        // Parses the time
        OffsetTime time2
            = OffsetTime.parse("15:20:30+07:00");
  
        // gets the time1
        System.out.println("time1: " + time1);
  
        // gets the time2
        System.out.println("time1: " + time2);
  
        System.out.println("time1 is equal to time2: "
                           + time1.isEqual(time2));
    }
}


Output:

time1: 15:30:30+07:00
time1: 15:20:30+07:00
time1 is equal to time2: false

Program 2 :




// Java program to demonstrate the isEqual() method
  
import java.time.OffsetTime;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // Parses the time
        OffsetTime time1
            = OffsetTime.parse("15:30:30+07:00");
  
        // Parses the time
        OffsetTime time2
            = OffsetTime.parse("15:30:30+07:00");
  
        // gets the time1
        System.out.println("time1: "
                           + time1);
  
        // gets the time2
        System.out.println("time1: "
                           + time2);
  
        System.out.println("time1 is equals to time2: "
                           + time1.isEqual(time2));
    }
}


Output:

time1: 15:30:30+07:00
time1: 15:30:30+07:00
time1 is equals to time2: true

Reference: https://www.tutorialspoint.com/javatime/javatime_offsettime_isequal.htm

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS