OffsetTime equals() method in Java with examples
The equals() method of OffsetTime class in Java checks if this time is equal to another time. returns true if they are equal or false if they are not.
Syntax:
public boolean equals(Object obj)
Parameter: This method accepts a single mandatory parameter obj which specifies the other time which will be compared with.
Return Value: It returns true if both the time are equal, else it returns false.
Below programs illustrate the equals() method:
Program 1 :
// Java program to demonstrate the equals() 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 offset time1 System.out.println("time1: " + time1); // gets the offset time2 System.out.println("time1: " + time2); System.out.println("time1 when compared" + " to time2 returns: " + time1.equals(time2)); } } |
time1: 15:30:30+07:00 time1: 15:30:30+07:00 time1 when compared to time2 returns: true
Program 2 :
// Java program to demonstrate the equals() 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("12:10:30+07:00"); // gets the offset time1 System.out.println("time1: " + time1); // gets the offset time2 System.out.println("time1: " + time2); System.out.println("time1 when compared" + " to time2 returns: " + time1.equals(time2)); } } |
time1: 15:30:30+07:00 time1: 12:10:30+07:00 time1 when compared to time2 returns: false
Reference: https://docs.oracle.com/javase/8/docs/api/java/time/OffsetTime.html#compareTo-java.time.OffsetTime-
Recommended Posts:
- OffsetTime until() Method in Java with Examples
- OffsetTime plus() method in Java with examples
- OffsetTime with() Method in Java with Examples
- OffsetTime now() method in Java with examples
- OffsetTime get() method in Java with examples
- OffsetTime from() method in Java with examples
- OffsetTime getMinute() method in Java with examples
- OffsetTime query() method in Java with examples
- OffsetTime getHour() method in Java with examples
- OffsetTime isBefore() method in Java with examples
- OffsetTime compareTo() method in Java with examples
- OffsetTime getOffset() method in Java with examples
- OffsetTime format() method in Java with examples
- OffsetTime range() method in Java with Examples
- OffsetTime adjustInto() method in Java with examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


