isBefore 方法

bool isBefore(
  1. DateTime other
)

判断此 DateTime 是否在 other 之前。

比较与时间是否在 UTC 或本地时区无关。

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

实现

external bool isBefore(DateTime other);