compareTo method

  1. @override
int compareTo(
  1. ZonedDateTime other
)
override

Compares this ZonedDateTime with another for ordering.

Comparison is based on the instant in time, not the local date-time. Two ZonedDateTime objects representing the same instant but in different timezones are considered equal.

Example:

final ny = ZonedDateTime.parse('2023-12-25T15:00:00-05:00[America/New_York]');
final london = ZonedDateTime.parse('2023-12-25T20:00:00+00:00[Europe/London]');

print(ny.compareTo(london)); // 0 (same instant)
print(ny == london); // true

Implementation

@override
int compareTo(ZonedDateTime other) {
  return toEpochMilli().compareTo(other.toEpochMilli());
}