Java 8 – How to compare two ZonedDateTime instances ?

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

1. Comparing two ZonedDateTime instances :

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

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

2. Examples for Comparing two ZonedDateTime :

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

2.1 Using compareTo(ChronoZonedDateTime) method :

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

CompareTwoZonedDateTimeUsingCompareToMethod.java

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

import java.time.ZoneId;
import java.time.ZonedDateTime;

public class CompareTwoZonedDateTimeUsingCompareToMethod {

	public static void main(String[] args) {

		// 1. get Current Zoned Date/time
		ZoneId zoneIdLocal = ZoneId.systemDefault();
		ZonedDateTime currentZonedDateTime = ZonedDateTime.of(2022, 8, 15, 12, 30, 30, 500, zoneIdLocal);
		System.out.println("1. Current Zoned Date/time is = " + currentZonedDateTime);


		// 2. form Past Date/time
		ZoneId zoneIdPast = ZoneId.of("Australia/Sydney");
		ZonedDateTime pastZonedDateTime = ZonedDateTime.of(2022, 8, 15, 12, 30, 30, 500, zoneIdPast);
		System.out.println("2. Past Zoned Date/time is = " + pastZonedDateTime);


		// 3. form Future Date/time
		ZoneId zoneIdFuture = ZoneId.of("America/Chicago");
		ZonedDateTime futureZonedDateTime = ZonedDateTime.of(2022, 8, 15, 12, 30, 30, 500, zoneIdFuture);
		System.out.println("3. Future Zoned Date/time is = " + futureZonedDateTime);



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


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


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


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


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

Output:

1. Current Zoned Date/time is = 2022-08-15T12:30:30.000000500+05:30[Asia/Calcutta]
2. Past Zoned Date/time is = 2022-08-15T12:30:30.000000500+10:00[Australia/Sydney]
3. Future Zoned Date/time is = 2022-08-15T12:30:30.000000500-05:00[America/Chicago]


4. Comparison with compareTo() method :- 

4.1 Current Zoned Date/time (2022-08-15T12:30:30.000000500+05:30[Asia/Calcutta]) 
	 is Older-than Future Zoned Date/time (2022-08-15T12:30:30.000000500-05:00[America/Chicago]) ? true
4.2 Current Zoned Date/time (2022-08-15T12:30:30.000000500+05:30[Asia/Calcutta]) 
	 is Latter-than Future Zoned Date/time (2022-08-15T12:30:30.000000500-05:00[America/Chicago]) ? false
4.3 Current Zoned Date/time (2022-08-15T12:30:30.000000500+05:30[Asia/Calcutta]) 
	 is Older than Past Zoned Date/time (2022-08-15T12:30:30.000000500+10:00[Australia/Sydney]) ? false
4.4 Current Zoned Date/time (2022-08-15T12:30:30.000000500+05:30[Asia/Calcutta]) 
	 is Latter-than Past Zoned Date/time (2022-08-15T12:30:30.000000500+10:00[Australia/Sydney]) ? true

2.2 Using isBefore(ChronoZonedDateTime) method :

CheckZonedDateTimeIsBeforeAnotherZonedDateTime.java

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

import java.time.ZoneId;
import java.time.ZonedDateTime;

public class CheckZonedDateTimeIsBeforeAnotherZonedDateTime {

	public static void main(String[] args) {

		// 1. get Local Zoned Date/time
		ZoneId zoneIdLocal = ZoneId.systemDefault();
		ZonedDateTime currentZonedDateTime = ZonedDateTime.of(2022, 8, 15, 12, 30, 30, 500, zoneIdLocal);
		System.out.println("1. Current Zoned Date/time is = " + currentZonedDateTime);


		// 2. form Past Date/time
		ZoneId zoneIdPast = ZoneId.of("Australia/Sydney");
		ZonedDateTime pastZonedDateTime = ZonedDateTime.of(2022, 8, 15, 12, 30, 30, 500, zoneIdPast);
		System.out.println("2. Past Zoned Date/time is = " + pastZonedDateTime);


		// 3. form Future Date/time
		ZoneId zoneIdFuture = ZoneId.of("America/Chicago");
		ZonedDateTime futureZonedDateTime = ZonedDateTime.of(2022, 8, 15, 12, 30, 30, 500, zoneIdFuture);
		System.out.println("3. Future Zoned Date/time is = " + futureZonedDateTime);



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


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


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


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


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


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


		// 4.6 check whether futureZonedDateTime isBefore pastZonedDateTime 
		boolean isBefore6 = futureZonedDateTime.isBefore(currentZonedDateTime);
		System.out.println("4.6 Future Zoned Date/time (" + futureZonedDateTime 
				+ ") \n\t\t is Before Past Zoned Date/time (" + pastZonedDateTime + ") ? "
				+ isBefore6);
	}
}

Output:

1. Current Zoned Date/time is = 2022-08-15T12:30:30.000000500+05:30[Asia/Calcutta]
2. Past Zoned Date/time is = 2022-08-15T12:30:30.000000500+10:00[Australia/Sydney]
3. Future Zoned Date/time is = 2022-08-15T12:30:30.000000500-05:00[America/Chicago]


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

4.1 Current Zoned Date/time (2022-08-15T12:30:30.000000500+05:30[Asia/Calcutta]) 
		 is Before Future Zoned Date/time (2022-08-15T12:30:30.000000500-05:00[America/Chicago]) ? true
4.2 Current Zoned Date/time (2022-08-15T12:30:30.000000500+05:30[Asia/Calcutta]) 
		 is Before Past Zoned Date/time (2022-08-15T12:30:30.000000500+10:00[Australia/Sydney]) ? false
4.3 Past Zoned Date/time (2022-08-15T12:30:30.000000500+10:00[Australia/Sydney]) 
		 is Before Current Zoned Date/time (2022-08-15T12:30:30.000000500+05:30[Asia/Calcutta]) ? true
4.4 Past Zoned Date/time (2022-08-15T12:30:30.000000500+10:00[Australia/Sydney]) 
		 is Before Future Zoned Date/time (2022-08-15T12:30:30.000000500-05:00[America/Chicago]) ? true
4.5 Future Zoned Date/time (2022-08-15T12:30:30.000000500-05:00[America/Chicago]) 
		 is Before Current Zoned Date/time (2022-08-15T12:30:30.000000500+05:30[Asia/Calcutta]) ? false
4.6 Future Zoned Date/time (2022-08-15T12:30:30.000000500-05:00[America/Chicago]) 
		 is Before Past Zoned Date/time (2022-08-15T12:30:30.000000500+10:00[Australia/Sydney]) ? false

2.3 Using isAfter(ChronoZonedDateTime) method :

CheckZonedDateTimeIsAfterAnotherZonedDateTime.java

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

import java.time.ZoneId;
import java.time.ZonedDateTime;

public class CheckZonedDateTimeIsAfterAnotherZonedDateTime {

	public static void main(String[] args) {

		// 1. get Current Zoned Date/time
		ZoneId zoneIdLocal = ZoneId.systemDefault();
		ZonedDateTime currentZonedDateTime = ZonedDateTime.of(2022, 8, 15, 12, 30, 30, 500, zoneIdLocal);
		System.out.println("1. Current Zoned Date/time is = " + currentZonedDateTime);


		// 2. form Past Date/time
		ZoneId zoneIdPast = ZoneId.of("Australia/Sydney");
		ZonedDateTime pastZonedDateTime = ZonedDateTime.of(2022, 8, 15, 12, 30, 30, 500, zoneIdPast);
		System.out.println("2. Past Zoned Date/time is = " + pastZonedDateTime);


		// 3. form Future Date/time
		ZoneId zoneIdFuture = ZoneId.of("America/Chicago");
		ZonedDateTime futureZonedDateTime = ZonedDateTime.of(2022, 8, 15, 12, 30, 30, 500, zoneIdFuture);
		System.out.println("3. Future Zoned Date/time is = " + futureZonedDateTime);



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


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


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


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


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


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


		// 4.6 check whether futureZonedDateTime isAfter pastZonedDateTime 
		boolean isAfter6 = futureZonedDateTime.isAfter(currentZonedDateTime);
		System.out.println("4.6 Future Date/time (" + futureZonedDateTime 
				+ ") \n\t\t is After Past Date/time (" + pastZonedDateTime + ") ? "
				+ isAfter6);
	}
}

Output:

1. Current Zoned Date/time is = 2022-08-15T12:30:30.000000500+05:30[Asia/Calcutta]
2. Past Zoned Date/time is = 2022-08-15T12:30:30.000000500+10:00[Australia/Sydney]
3. Future Zoned Date/time is = 2022-08-15T12:30:30.000000500-05:00[America/Chicago]


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

4.1 Current Date/time (2022-08-15T12:30:30.000000500+05:30[Asia/Calcutta]) 
		 is After Future Date/time (2022-08-15T12:30:30.000000500-05:00[America/Chicago]) ? false
4.2 Current Date/time (2022-08-15T12:30:30.000000500+05:30[Asia/Calcutta]) 
		 is After Past Date/time (2022-08-15T12:30:30.000000500+10:00[Australia/Sydney]) ? true
4.3 Past Date/time (2022-08-15T12:30:30.000000500+10:00[Australia/Sydney]) 
		 is After Current Date/time (2022-08-15T12:30:30.000000500+05:30[Asia/Calcutta]) ? false
4.4 Past Date/time (2022-08-15T12:30:30.000000500+10:00[Australia/Sydney]) 
		 is After Future Date/time (2022-08-15T12:30:30.000000500-05:00[America/Chicago]) ? false
4.5 Future Date/time (2022-08-15T12:30:30.000000500-05:00[America/Chicago]) 
		 is After Current Date/time (2022-08-15T12:30:30.000000500+05:30[Asia/Calcutta]) ? true
4.6 Future Date/time (2022-08-15T12:30:30.000000500-05:00[America/Chicago]) 
		 is After Past Date/time (2022-08-15T12:30:30.000000500+10:00[Australia/Sydney]) ? true

2.4 Using isEqual(ChronoZonedDateTime) method :

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

CheckTwoZonedDateTimeAreEqualUsingIsEqualMethod.java

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

import java.time.ZoneId;
import java.time.ZonedDateTime;

public class CheckTwoZonedDateTimeAreEqualUsingIsEqualMethod {

	public static void main(String[] args) {

		// 1. get Current Zoned Date/time 1
		ZoneId zoneIdLocal = ZoneId.systemDefault();
		ZonedDateTime currentZonedDateTime = ZonedDateTime.of(2022, 8, 15, 12, 30, 30, 500, zoneIdLocal);
		System.out.println("1. Current Zoned Date/time is = " + currentZonedDateTime);


		// 2. get Current Zoned Date/time 2
		ZonedDateTime currentZonedDateTime2 = ZonedDateTime.of(2022, 8, 15, 12, 30, 30, 500, zoneIdLocal);
		System.out.println("2. Current Zoned Date/time is = " + currentZonedDateTime2);


		// 3. form Past Date/time
		ZoneId zoneIdPast = ZoneId.of("Australia/Sydney");
		ZonedDateTime pastZonedDateTime = ZonedDateTime.of(2022, 8, 15, 12, 30, 30, 500, zoneIdPast);
		System.out.println("3. Past Zoned Date/time is = " + pastZonedDateTime);


		// 4. form Future Date/time
		ZoneId zoneIdFuture = ZoneId.of("America/Chicago");
		ZonedDateTime futureZonedDateTime = ZonedDateTime.of(2022, 8, 15, 12, 30, 30, 500, zoneIdFuture);
		System.out.println("4. Future Zoned Date/time is = " + futureZonedDateTime);



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


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


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


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

Output:

1. Current Zoned Date/time is = 2022-08-15T12:30:30.000000500+05:30[Asia/Calcutta]
2. Current Zoned Date/time is = 2022-08-15T12:30:30.000000500+05:30[Asia/Calcutta]
3. Past Zoned Date/time is = 2022-08-15T12:30:30.000000500+10:00[Australia/Sydney]
4. Future Zoned Date/time is = 2022-08-15T12:30:30.000000500-05:00[America/Chicago]


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

5.1 Current Zoned Date/time (2022-08-15T12:30:30.000000500+05:30[Asia/Calcutta]) 
	 & Current Zoned Date/time (2022-08-15T12:30:30.000000500+05:30[Asia/Calcutta]) are equal ?	 true
5.2 Current Zoned Date/time (2022-08-15T12:30:30.000000500+05:30[Asia/Calcutta]) 
	 & Past Zoned Date/time (2022-08-15T12:30:30.000000500+10:00[Australia/Sydney]) are equal ?	 false
5.3 Current Zoned Date/time (2022-08-15T12:30:30.000000500+05:30[Asia/Calcutta]) 
	 & Future Zoned Date/time (2022-08-15T12:30:30.000000500-05:00[America/Chicago]) are equal ?	 false

2.5 Using equals(Object) method :

  • This method checks if invoking ZonedDateTime is equal to the another ZonedDateTime
    1. Return true, only if both invoking ZonedDateTime & specified ZonedDateTime 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.zoneddatetime.examples;

import java.time.ZoneId;
import java.time.ZonedDateTime;

public class CheckTwoZonedDateTimeAreEqualUsingEqualsMethod {

	public static void main(String[] args) {

		// 1. get Current Zoned Date/time 1
		ZoneId zoneIdLocal = ZoneId.systemDefault();
		ZonedDateTime currentZonedDateTime = ZonedDateTime.of(2022, 8, 15, 12, 30, 30, 500, zoneIdLocal);
		System.out.println("1. Current Zoned Date/time is = " + currentZonedDateTime);


		// 2. get Current Zoned Date/time 2
		ZonedDateTime currentZonedDateTime2 = ZonedDateTime.of(2022, 8, 15, 12, 30, 30, 500, zoneIdLocal);
		System.out.println("2. Current Zoned Date/time is = " + currentZonedDateTime2);


		// 3. form Past Date/time
		ZoneId zoneIdPast = ZoneId.of("Australia/Sydney");
		ZonedDateTime pastZonedDateTime = ZonedDateTime.of(2022, 8, 15, 12, 30, 30, 500, zoneIdPast);
		System.out.println("3. Past Zoned Date/time is = " + pastZonedDateTime);


		// 4. form Future Date/time
		ZoneId zoneIdFuture = ZoneId.of("America/Chicago");
		ZonedDateTime futureZonedDateTime = ZonedDateTime.of(2022, 8, 15, 12, 30, 30, 500, zoneIdFuture);
		System.out.println("4. Future Zoned Date/time is = " + futureZonedDateTime);



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


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


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


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

Output:

1. Current Zoned Date/time is = 2022-08-15T12:30:30.000000500+05:30[Asia/Calcutta]
2. Current Zoned Date/time is = 2022-08-15T12:30:30.000000500+05:30[Asia/Calcutta]
3. Past Zoned Date/time is = 2022-08-15T12:30:30.000000500+10:00[Australia/Sydney]
4. Future Zoned Date/time is = 2022-08-15T12:30:30.000000500-05:00[America/Chicago]


5. Check two ZonedDateTime are equal using isEqual() method :- 

5.1 Current Zoned Date/time (2022-08-15T12:30:30.000000500+05:30[Asia/Calcutta]) 
	 & Current Zoned Date/time (2022-08-15T12:30:30.000000500+05:30[Asia/Calcutta]) are equal ?	 true
5.2 Current Zoned Date/time (2022-08-15T12:30:30.000000500+05:30[Asia/Calcutta]) 
	 & Past Zoned Date/time (2022-08-15T12:30:30.000000500+10:00[Australia/Sydney]) are equal ?	 false
5.3 Current Zoned Date/time (2022-08-15T12:30:30.000000500+05:30[Asia/Calcutta]) 
	 & Future Zoned Date/time (2022-08-15T12:30:30.000000500-05:00[America/Chicago]) are equal ?	 false

Related Articles:

References:

Happy Coding !!
Happy Learning !!

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