Java 8 – How to compare two OffsetDateTime instances ?

In this article, we will discuss different ways to compare two instances of OffsetDateTime in Java 1.8 version

1. Comparing two OffsetDateTime instances :

There are different methods available to compare two OffsetDateTime instances, those are –

  1. compareTo(OffsetDateTime) –
    • This method compares invoking OffsetDateTime with another OffsetDateTime
  2. isBefore(OffsetDateTime) –
    • This method checks if invoking OffsetDateTime is before the specified OffsetDateTime
  3. isAfter(OffsetDateTime) –
    • This method checks if invoking OffsetDateTime is after the specified OffsetDateTime
  4. isEqual(OffsetDateTime) –
    • This method checks if invoking OffsetDateTime is equal to the specified OffsetDateTime
  5. equals(Object) –
    • This method checks if invoking OffsetDateTimeis equal to another OffsetDateTime

2. Examples for Comparing two OffsetDateTime :

  1. Using compareTo(OffsetDateTime) method
  2. Using isBefore(OffsetDateTime) method
  3. Using isAfter(OffsetDateTime) method
  4. Using isEqual(OffsetDateTime) method
  5. Using equals(Object) method

2.1 Using compareTo(OffsetDateTime) method :

  • This method compares invoking OffsetDateTime with another OffsetDateTime and returns integer value based on the comparison
    1. Returns Zero, if both OffsetDateTime in comparison are equal
    2. Returns Positive value, if invoking OffsetDateTime is latter-than (greater-than) the specified OffsetDateTime
    3. Returns Negative value, if invoking OffsetDateTime is earlier-than (lesser-than) the specified OffsetDateTime

CompareTwoOffsetDateTimeUsingCompareToMethod.java

package in.bench.resources.java8.offsetdatetime.examples;

import java.time.OffsetDateTime;
import java.time.ZoneOffset;

public class CompareTwoOffsetDateTimeUsingCompareToMethod {

	public static void main(String[] args) {

		// 1. get Local Offset Date/time
		ZoneOffset zoneOffsetLocal = ZoneOffset.of("+05:30");
		OffsetDateTime currentOffsetDateTime = OffsetDateTime
				.of(2022, 8, 15, 12, 30, 30, 500, zoneOffsetLocal);
		System.out.println("1. Current Offset Date/time is = " + currentOffsetDateTime);


		// 2. form Past Offset Date/time
		ZoneOffset zoneOffsetPast = ZoneOffset.of("+10:30");
		OffsetDateTime pastOffsetDateTime = OffsetDateTime
				.of(2022, 8, 15, 12, 30, 30, 500, zoneOffsetPast);
		System.out.println("2. Past Offset Date/time is = " + pastOffsetDateTime);


		// 3. form Future Offset Date/time
		ZoneOffset zoneOffsetFuture = ZoneOffset.of("-09:30");
		OffsetDateTime futureOffsetDateTime = OffsetDateTime
				.of(2022, 8, 15, 12, 30, 30, 500, zoneOffsetFuture);
		System.out.println("3. Future Offset Date/time is = " + futureOffsetDateTime);



		// 4. LocalDateTime comparison using compareTo() method
		System.out.println("\n\n4. Comparison with compareTo() method :- \n");


		// 4.1 check whether currentOffsetDateTime Older-than futureOffsetDateTime
		int compareTo1 = currentOffsetDateTime.compareTo(futureOffsetDateTime);
		System.out.println("4.1 Current Offset Date/time (" + currentOffsetDateTime 
				+ ") \n\t is Older-than Future Offset Date/time (" + futureOffsetDateTime + ") ? " 
				+ (compareTo1 < 0));


		// 4.2 check whether currentOffsetDateTime Latter-than futureOffsetDateTime
		int compareTo2 = currentOffsetDateTime.compareTo(futureOffsetDateTime);
		System.out.println("4.2 Current Offset Date/time (" + currentOffsetDateTime 
				+ ") \n\t is Latter-than Future Offset Date/time (" + futureOffsetDateTime + ") ? " 
				+ (compareTo2 > 0));


		// 4.3 check whether currentOffsetDateTime Older-than pastOffsetDateTime
		int compareTo3 = currentOffsetDateTime.compareTo(pastOffsetDateTime);
		System.out.println("4.3 Current Offset Date/time (" + currentOffsetDateTime 
				+ ") \n\t is Older than Past Offset Date/time (" + pastOffsetDateTime + ") ? " 
				+ (compareTo3 < 0));


		// 4.4 check whether currentOffsetDateTime Latter-than pastOffsetDateTime
		int compareTo4 = currentOffsetDateTime.compareTo(pastOffsetDateTime);
		System.out.print("4.4 Current Offset Date/time (" + currentOffsetDateTime 
				+ ") \n\t is Latter-than Past Offset Date/time (" + pastOffsetDateTime + ") ? " 
				+ (compareTo4 > 0));
	}
}

Output:

1. Current Offset Date/time is = 2022-08-15T12:30:30.000000500+05:30
2. Past Offset Date/time is = 2022-08-15T12:30:30.000000500+10:30
3. Future Offset Date/time is = 2022-08-15T12:30:30.000000500-09:30


4. Comparison with compareTo() method :- 

4.1 Current Offset Date/time (2022-08-15T12:30:30.000000500+05:30) 
	 is Older-than Future Offset Date/time (2022-08-15T12:30:30.000000500-09:30) ? true
4.2 Current Offset Date/time (2022-08-15T12:30:30.000000500+05:30) 
	 is Latter-than Future Offset Date/time (2022-08-15T12:30:30.000000500-09:30) ? false
4.3 Current Offset Date/time (2022-08-15T12:30:30.000000500+05:30) 
	 is Older than Past Offset Date/time (2022-08-15T12:30:30.000000500+10:30) ? false
4.4 Current Offset Date/time (2022-08-15T12:30:30.000000500+05:30) 
	 is Latter-than Past Offset Date/time (2022-08-15T12:30:30.000000500+10:30) ? true

2.2 Using isBefore(OffsetDateTime) method :

  • This method checks if invoking OffsetDateTime is before the specified OffsetDateTime
    1. Returns true, if invoking OffsetDateTime is before the specified OffsetDateTime
    2. Returns false, if invoking OffsetDateTime is not before the specified OffsetDateTime
    3. Always returns false for self-comparing OffsetDateTime objects
  • Read Java 8 – How to check whether an OffsetDateTime is Before another OffsetDateTime ? for more details and examples

CheckOffsetDateTimeIsBeforeAnotherOffsetDateTime.java

package in.bench.resources.java8.offsetdatetime.examples;

import java.time.OffsetDateTime;
import java.time.ZoneOffset;

public class CheckOffsetDateTimeIsBeforeAnotherOffsetDateTime {

	public static void main(String[] args) {

		// 1. get Local Offset Date/time
		ZoneOffset zoneOffsetLocal = ZoneOffset.of("+05:30");
		OffsetDateTime currentOffsetDateTime = OffsetDateTime
				.of(2022, 8, 15, 12, 30, 30, 500, zoneOffsetLocal);
		System.out.println("1. Current Offset Date/time is = " + currentOffsetDateTime);


		// 2. form Past Offset Date/time
		ZoneOffset zoneOffsetPast = ZoneOffset.of("+10:30");
		OffsetDateTime pastOffsetDateTime = OffsetDateTime
				.of(2022, 8, 15, 12, 30, 30, 500, zoneOffsetPast);
		System.out.println("2. Past Offset Date/time is = " + pastOffsetDateTime);


		// 3. form Future Offset Date/time
		ZoneOffset zoneOffsetFuture = ZoneOffset.of("-09:30");
		OffsetDateTime futureOffsetDateTime = OffsetDateTime
				.of(2022, 8, 15, 12, 30, 30, 500, zoneOffsetFuture);
		System.out.println("3. Future Offset Date/time is = " + futureOffsetDateTime);



		// 4. isBefore() - OffsetDateTime comparison
		System.out.println("\n\n4. Comparing 2 OffsetDateTime using isBefore() method :- \n");


		// 4.1 check whether currentOffsetDateTime isBefore futureOffsetDateTime
		boolean isBefore1 = currentOffsetDateTime.isBefore(futureOffsetDateTime);
		System.out.println("4.1 Current Offset Date/time (" + currentOffsetDateTime 
				+ ") \n\t\t is Before Future Offset Date/time (" + futureOffsetDateTime + ") ? "
				+ isBefore1);


		// 4.2 check whether currentOffsetDateTime isBefore pastOffsetDateTime
		boolean isBefore2 = currentOffsetDateTime.isBefore(pastOffsetDateTime);
		System.out.println("4.2 Current Offset Date/time (" + currentOffsetDateTime 
				+ ") \n\t\t is Before Past Offset Date/time (" + pastOffsetDateTime + ") ? "
				+ isBefore2);


		// 4.3 check whether pastOffsetDateTime isBefore currentOffsetDateTime 
		boolean isBefore3 = pastOffsetDateTime.isBefore(currentOffsetDateTime);
		System.out.println("4.3 Past Offset Date/time (" + pastOffsetDateTime 
				+ ") \n\t\t is Before Current Offset Date/time (" + currentOffsetDateTime + ") ? "
				+ isBefore3);


		// 4.4 check whether pastOffsetDateTime isBefore futureOffsetDateTime 
		boolean isBefore4 = pastOffsetDateTime.isBefore(futureOffsetDateTime);
		System.out.println("4.4 Past Offset Date/time (" + pastOffsetDateTime 
				+ ") \n\t\t is Before Future Offset Date/time (" + futureOffsetDateTime + ") ? "
				+ isBefore4);


		// 4.5 check whether futureOffsetDateTime isBefore currentOffsetDateTime 
		boolean isBefore5 = futureOffsetDateTime.isBefore(currentOffsetDateTime);
		System.out.println("4.5 Future Offset Date/time (" + futureOffsetDateTime 
				+ ") \n\t\t is Before Current Offset Date/time (" + currentOffsetDateTime + ") ? "
				+ isBefore5);


		// 4.6 check whether futureOffsetDateTime isBefore pastOffsetDateTime 
		boolean isBefore6 = futureOffsetDateTime.isBefore(currentOffsetDateTime);
		System.out.print("4.6 Future Offset Date/time (" + futureOffsetDateTime 
				+ ") \n\t\t is Before Past Offset Date/time (" + pastOffsetDateTime + ") ? "
				+ isBefore6);
	}
}

Output:

1. Current Offset Date/time is = 2022-08-15T12:30:30.000000500+05:30
2. Past Offset Date/time is = 2022-08-15T12:30:30.000000500+10:30
3. Future Offset Date/time is = 2022-08-15T12:30:30.000000500-09:30


4. Comparing 2 OffsetDateTime using isBefore() method :- 

4.1 Current Offset Date/time (2022-08-15T12:30:30.000000500+05:30) 
		 is Before Future Offset Date/time (2022-08-15T12:30:30.000000500-09:30) ? true
4.2 Current Offset Date/time (2022-08-15T12:30:30.000000500+05:30) 
		 is Before Past Offset Date/time (2022-08-15T12:30:30.000000500+10:30) ? false
4.3 Past Offset Date/time (2022-08-15T12:30:30.000000500+10:30) 
		 is Before Current Offset Date/time (2022-08-15T12:30:30.000000500+05:30) ? true
4.4 Past Offset Date/time (2022-08-15T12:30:30.000000500+10:30) 
		 is Before Future Offset Date/time (2022-08-15T12:30:30.000000500-09:30) ? true
4.5 Future Offset Date/time (2022-08-15T12:30:30.000000500-09:30) 
		 is Before Current Offset Date/time (2022-08-15T12:30:30.000000500+05:30) ? false
4.6 Future Offset Date/time (2022-08-15T12:30:30.000000500-09:30) 
		 is Before Past Offset Date/time (2022-08-15T12:30:30.000000500+10:30) ? false

2.3 Using isAfter(OffsetDateTime) method :

  • This method checks if invoking OffsetDateTime is after the specified OffsetDateTime
    1. Returns true, if invoking OffsetDateTime is after the specified OffsetDateTime
    2. Returns false, if invoking OffsetDateTime is not after the specified OffsetDateTime
    3. Always returns false for self-comparing OffsetDateTime objects
  • Read Java 8 – How to check whether an OffsetDateTime is After another OffsetDateTime ? for more details and examples

CheckOffsetDateTimeIsAfterAnotherOffsetDateTime.java

package in.bench.resources.java8.offsetdatetime.examples;

import java.time.OffsetDateTime;
import java.time.ZoneOffset;

public class CheckOffsetDateTimeIsAfterAnotherOffsetDateTime {

	public static void main(String[] args) {

		// 1. get Local Offset Date/time
		ZoneOffset zoneOffsetLocal = ZoneOffset.of("+05:30");
		OffsetDateTime currentOffsetDateTime = OffsetDateTime
				.of(2022, 8, 15, 12, 30, 30, 500, zoneOffsetLocal);
		System.out.println("1. Current Offset Date/time is = " + currentOffsetDateTime);


		// 2. form Past Offset Date/time
		ZoneOffset zoneOffsetPast = ZoneOffset.of("+10:30");
		OffsetDateTime pastOffsetDateTime = OffsetDateTime
				.of(2022, 8, 15, 12, 30, 30, 500, zoneOffsetPast);
		System.out.println("2. Past Offset Date/time is = " + pastOffsetDateTime);


		// 3. form Future Offset Date/time
		ZoneOffset zoneOffsetFuture = ZoneOffset.of("-09:30");
		OffsetDateTime futureOffsetDateTime = OffsetDateTime
				.of(2022, 8, 15, 12, 30, 30, 500, zoneOffsetFuture);
		System.out.println("3. Future Offset Date/time is = " + futureOffsetDateTime);



		// 4. isAfter() - LocalDateTime comparison
		System.out.println("\n\n4. Comparing 2 LocalDateTime using isAfter() method :- \n");


		// 4.1 check whether currentOffsetDateTime isAfter futureOffsetDateTime
		boolean isAfter1 = currentOffsetDateTime.isAfter(futureOffsetDateTime);
		System.out.println("4.1 Current Offset Date/time (" + currentOffsetDateTime 
				+ ") \n\t\t is After Future Offset Date/time (" + futureOffsetDateTime + ") ? "
				+ isAfter1);


		// 4.2 check whether currentOffsetDateTime isAfter pastOffsetDateTime
		boolean isAfter2 = currentOffsetDateTime.isAfter(pastOffsetDateTime);
		System.out.println("4.2 Current Offset Date/time (" + currentOffsetDateTime 
				+ ") \n\t\t is After Past Offset Date/time (" + pastOffsetDateTime + ") ? "
				+ isAfter2);


		// 4.3 check whether pastOffsetDateTime isAfter currentOffsetDateTime 
		boolean isAfter3 = pastOffsetDateTime.isAfter(currentOffsetDateTime);
		System.out.println("4.3 Past Offset Date/time (" + pastOffsetDateTime 
				+ ") \n\t\t is After Offset Current Date/time (" + currentOffsetDateTime + ") ? "
				+ isAfter3);


		// 4.4 check whether pastOffsetDateTime isAfter futureOffsetDateTime 
		boolean isAfter4 = pastOffsetDateTime.isAfter(futureOffsetDateTime);
		System.out.println("4.4 Past Offset Date/time (" + pastOffsetDateTime 
				+ ") \n\t\t is After Future Offset Date/time (" + futureOffsetDateTime + ") ? "
				+ isAfter4);


		// 4.5 check whether futureOffsetDateTime isAfter currentOffsetDateTime 
		boolean isAfter5 = futureOffsetDateTime.isAfter(currentOffsetDateTime);
		System.out.println("4.5 Future Offset Date/time (" + futureOffsetDateTime 
				+ ") \n\t\t is After Current Offset Date/time (" + currentOffsetDateTime + ") ? "
				+ isAfter5);


		// 4.6 check whether futureOffsetDateTime isAfter pastOffsetDateTime 
		boolean isAfter6 = futureOffsetDateTime.isAfter(currentOffsetDateTime);
		System.out.print("4.6 Future Offset Date/time (" + futureOffsetDateTime 
				+ ") \n\t\t is After Past Offset Date/time (" + pastOffsetDateTime + ") ? "
				+ isAfter6);
	}
}

Output:

1. Current Offset Date/time is = 2022-08-15T12:30:30.000000500+05:30
2. Past Offset Date/time is = 2022-08-15T12:30:30.000000500+10:30
3. Future Offset Date/time is = 2022-08-15T12:30:30.000000500-09:30


4. Comparing 2 LocalDateTime using isAfter() method :- 

4.1 Current Offset Date/time (2022-08-15T12:30:30.000000500+05:30) 
		 is After Future Offset Date/time (2022-08-15T12:30:30.000000500-09:30) ? false
4.2 Current Offset Date/time (2022-08-15T12:30:30.000000500+05:30) 
		 is After Past Offset Date/time (2022-08-15T12:30:30.000000500+10:30) ? true
4.3 Past Offset Date/time (2022-08-15T12:30:30.000000500+10:30) 
		 is After Offset Current Date/time (2022-08-15T12:30:30.000000500+05:30) ? false
4.4 Past Offset Date/time (2022-08-15T12:30:30.000000500+10:30) 
		 is After Future Offset Date/time (2022-08-15T12:30:30.000000500-09:30) ? false
4.5 Future Offset Date/time (2022-08-15T12:30:30.000000500-09:30) 
		 is After Current Offset Date/time (2022-08-15T12:30:30.000000500+05:30) ? true
4.6 Future Offset Date/time (2022-08-15T12:30:30.000000500-09:30) 
		 is After Past Offset Date/time (2022-08-15T12:30:30.000000500+10:30) ? true

2.4 Using isEqual(OffsetDateTime) method :

  • This method checks if invoking OffsetDateTime is equal to the specified OffsetDateTime
    1. Return true, only if both invoking OffsetDateTime & specified OffsetDateTime are same
    2. Return false, for all other cases

CheckTwoZonedDateTimeAreEqualUsingIsEqualMethod.java

package in.bench.resources.java8.offsetdatetime.examples;

import java.time.OffsetDateTime;
import java.time.ZoneOffset;

public class CheckTwoOffsetDateTimeAreEqualUsingIsEqualMethod {

	public static void main(String[] args) {

		// 1. get Local Offset Date/time
		ZoneOffset zoneOffsetLocal = ZoneOffset.of("+05:30");
		OffsetDateTime currentOffsetDateTime = OffsetDateTime
				.of(2022, 8, 15, 12, 30, 30, 500, zoneOffsetLocal);
		System.out.println("1. Current Offset Date/time is = " + currentOffsetDateTime);


		// 2. get Local Offset Date/time
		OffsetDateTime currentOffsetDateTime2 = OffsetDateTime
				.of(2022, 8, 15, 12, 30, 30, 500, zoneOffsetLocal);
		System.out.println("2. Current Offset Date/time is = " + currentOffsetDateTime2);


		// 3. form Past Offset Date/time
		ZoneOffset zoneOffsetPast = ZoneOffset.of("+10:30");
		OffsetDateTime pastOffsetDateTime = OffsetDateTime
				.of(2022, 8, 15, 12, 30, 30, 500, zoneOffsetPast);
		System.out.println("3. Past Offset Date/time is = " + pastOffsetDateTime);


		// 4. form Future Offset Date/time
		ZoneOffset zoneOffsetFuture = ZoneOffset.of("-09:30");
		OffsetDateTime futureOffsetDateTime = OffsetDateTime
				.of(2022, 8, 15, 12, 30, 30, 500, zoneOffsetFuture);
		System.out.println("4. Future Offset Date/time is = " + futureOffsetDateTime);



		// 5. OffsetDateTime comparison using isEqual() method
		System.out.println("\n\n5. Check 2 OffsetDateTime are equal using isEqual() method :- \n");


		// 5.1 check whether currentOffsetDateTime & currentOffsetDateTime2 are same ?
		boolean isEqual1 = currentOffsetDateTime.isEqual(currentOffsetDateTime2);
		System.out.println("5.1 Current Offset Date/time (" + currentOffsetDateTime 
				+ ") \n\t & Current Offset Date/time (" + currentOffsetDateTime2 + ") are equal ?\t "
				+ isEqual1);


		// 5.2 check whether currentOffsetDateTime & pastOffsetDateTime are same ?
		boolean isEqual2 = currentOffsetDateTime.isEqual(pastOffsetDateTime);
		System.out.println("5.2 Current Offset Date/time (" + currentOffsetDateTime 
				+ ") \n\t & Past Offset Date/time (" + pastOffsetDateTime + ") are equal ?\t "
				+ isEqual2);


		// 5.3 check whether currentOffsetDateTime & futureOffsetDateTime are same ?
		boolean isEqual3 = currentOffsetDateTime.isEqual(futureOffsetDateTime);
		System.out.print("5.3 Current Offset Date/time (" + currentOffsetDateTime 
				+ ") \n\t & Future Offset Date/time (" + futureOffsetDateTime + ") are equal ?\t "
				+ isEqual3);
	}
}

Output:

1. Current Offset Date/time is = 2022-08-15T12:30:30.000000500+05:30
2. Current Offset Date/time is = 2022-08-15T12:30:30.000000500+05:30
3. Past Offset Date/time is = 2022-08-15T12:30:30.000000500+10:30
4. Future Offset Date/time is = 2022-08-15T12:30:30.000000500-09:30


5. Check 2 OffsetDateTime are equal using isEqual() method :- 

5.1 Current Offset Date/time (2022-08-15T12:30:30.000000500+05:30) 
	 & Current Offset Date/time (2022-08-15T12:30:30.000000500+05:30) are equal ?	 true
5.2 Current Offset Date/time (2022-08-15T12:30:30.000000500+05:30) 
	 & Past Offset Date/time (2022-08-15T12:30:30.000000500+10:30) are equal ?	 false
5.3 Current Offset Date/time (2022-08-15T12:30:30.000000500+05:30) 
	 & Future Offset Date/time (2022-08-15T12:30:30.000000500-09:30) are equal ?	 false

2.5 Using equals(Object) method :

  • This method checks if invoking OffsetDateTime is equal to the another OffsetDateTime
    1. Return true, only if both invoking OffsetDateTime & specified OffsetDateTime are same
    2. Return false, for all other cases
  • Note: this illustration very much similar to above 2.4 except that it uses equals(Object) method for comparison

CheckTwoZonedDateTimeAreEqualUsingEqualsMethod.java

package in.bench.resources.java8.offsetdatetime.examples;

import java.time.OffsetDateTime;
import java.time.ZoneOffset;

public class CheckTwoOffsetDateTimeAreEqualUsingEqualsMethod {

	public static void main(String[] args) {

		// 1. get Local Offset Date/time
		ZoneOffset zoneOffsetLocal = ZoneOffset.of("+05:30");
		OffsetDateTime currentOffsetDateTime = OffsetDateTime
				.of(2022, 8, 15, 12, 30, 30, 500, zoneOffsetLocal);
		System.out.println("1. Current Offset Date/time is = " + currentOffsetDateTime);


		// 2. get Local Offset Date/time
		OffsetDateTime currentOffsetDateTime2 = OffsetDateTime
				.of(2022, 8, 15, 12, 30, 30, 500, zoneOffsetLocal);
		System.out.println("2. Current Offset Date/time is = " + currentOffsetDateTime2);


		// 3. form Past Offset Date/time
		ZoneOffset zoneOffsetPast = ZoneOffset.of("+10:30");
		OffsetDateTime pastOffsetDateTime = OffsetDateTime
				.of(2022, 8, 15, 12, 30, 30, 500, zoneOffsetPast);
		System.out.println("3. Past Offset Date/time is = " + pastOffsetDateTime);


		// 4. form Future Offset Date/time
		ZoneOffset zoneOffsetFuture = ZoneOffset.of("-09:30");
		OffsetDateTime futureOffsetDateTime = OffsetDateTime
				.of(2022, 8, 15, 12, 30, 30, 500, zoneOffsetFuture);
		System.out.println("4. Future Offset Date/time is = " + futureOffsetDateTime);



		// 5. OffsetDateTime comparison using isEqual() method
		System.out.println("\n\n5. Check two OffsetDateTime are equal using equals() method :- \n");


		// 5.1 check whether currentOffsetDateTime & currentOffsetDateTime2 are same ?
		boolean equals1 = currentOffsetDateTime.equals(currentOffsetDateTime2);
		System.out.println("5.1 Current Offset Date/time (" + currentOffsetDateTime 
				+ ") \n\t & Current Offset Date/time (" + currentOffsetDateTime2 + ") are equal ?\t "
				+ equals1);


		// 5.2 check whether currentOffsetDateTime & pastOffsetDateTime are same ?
		boolean equals2 = currentOffsetDateTime.equals(pastOffsetDateTime);
		System.out.println("5.2 Current Offset Date/time (" + currentOffsetDateTime 
				+ ") \n\t & Past Offset Date/time (" + pastOffsetDateTime + ") are equal ?\t "
				+ equals2);


		// 5.3 check whether currentOffsetDateTime & futureOffsetDateTime are same ?
		boolean equals3 = currentOffsetDateTime.equals(futureOffsetDateTime);
		System.out.print("5.3 Current Offset Date/time (" + currentOffsetDateTime 
				+ ") \n\t & Future Offset Date/time (" + futureOffsetDateTime + ") are equal ?\t "
				+ equals3);
	}
}

Output:

1. Current Offset Date/time is = 2022-08-15T12:30:30.000000500+05:30
2. Current Offset Date/time is = 2022-08-15T12:30:30.000000500+05:30
3. Past Offset Date/time is = 2022-08-15T12:30:30.000000500+10:30
4. Future Offset Date/time is = 2022-08-15T12:30:30.000000500-09:30


5. Check two OffsetDateTime are equal using equals() method :- 

5.1 Current Offset Date/time (2022-08-15T12:30:30.000000500+05:30) 
	 & Current Offset Date/time (2022-08-15T12:30:30.000000500+05:30) are equal ?	 true
5.2 Current Offset Date/time (2022-08-15T12:30:30.000000500+05:30) 
	 & Past Offset Date/time (2022-08-15T12:30:30.000000500+10:30) are equal ?	 false
5.3 Current Offset Date/time (2022-08-15T12:30:30.000000500+05:30) 
	 & Future Offset Date/time (2022-08-15T12:30:30.000000500-09:30) are equal ?	 false

Related Articles:

References:

Happy Coding !!
Happy Learning !!

Java 8 – How to find difference between two OffsetDateTime using Period & Duration ?
Java 8 – How to check whether an OffsetDateTime is After another OffsetDateTime ?