isBefore method

bool isBefore(
  1. DateTime other
)

Whether this DateTime occurs before other.

The comparison is independent of whether the time is in UTC or in the local time zone.

final now = DateTime.now();
final earlier = now.subtract(const Duration(seconds: 5));
print(earlier.isBefore(now)); // true
print(!now.isBefore(now)); // true

// This relation stays the same, even when changing timezones.
print(earlier.isBefore(now.toUtc())); // true
print(earlier.toUtc().isBefore(now)); // true

print(!now.toUtc().isBefore(now)); // true
print(!now.isBefore(now.toUtc())); // true

Implementation

external bool isBefore(DateTime other);