compareTo方法
- DateTime other
override
比较此DateTime对象与other
,如果值相等则返回零。
compareTo函数返回
- 一个负值,如果此DateTime isBefore
other
。 - 如果此DateTime isAtSameMomentAs
other
,则返回0
, - 否则返回正值(当此DateTime isAfter
other
时)。
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
实现
external int compareTo(DateTime other);