compareTo method - DateTime class - dart:core library (original) (raw)

int compareTo(

  1. DateTime other )

override

Compares this DateTime object to other, returning zero if the values are equal.

A compareTo function returns:

final now = DateTime.now();
final future = now.add(const Duration(days: 2));
final past = now.subtract(const Duration(days: 2));
final newDate = now.toUtc();

print(now.compareTo(future)); // -1
print(now.compareTo(past)); // 1
print(now.compareTo(newDate)); // 0

Implementation

external int compareTo(DateTime other);