Spec-Zone.ru › Dart 2

dart:core

Метод compareTo

int compareTo(
  1. DateTime other
)
override

Сравнивает этот объект DateTime с other, возвращая ноль, если значения равны.

Функция compareTo возвращает:

  • отрицательное значение, если этот DateTime предшествует other.
  • ноль, если этот DateTime совпадает по моменту с other, и
  • положительное значение в противном случае (когда этот DateTime последуют 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);

© 2012 the Dart project authors
Licensed under the BSD 3-Clause "New" or "Revised" License.
https://api.dart.dev/stable/2.18.5/dart-core/DateTime/compareTo.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API