whenwas 1.1.0 copy "whenwas: ^1.1.0" to clipboard
whenwas: ^1.1.0 copied to clipboard

Calculates how many years, months, days, ... ago a DateTime is.

example/whenwas_example.dart

import 'package:whenwas/whenwas.dart';

main() {
  var dateInThePast = DateTime.now().subtract(
    Duration(
      milliseconds: 2,
      seconds: 15,
      minutes: 27,
      hours: 4,
      days: 29
    )
  );

  // 29 days ago
  print(When(dateInThePast));

  // custom format:
  dateInThePast = dateInThePast.subtract(Duration(days: 365 * 4));
  var time = When(dateInThePast).toTime();
  if (time.unit == TimeUnit.YEAR) {
    // 4 super long years ago
    print('${time.amount} super long ${time.unit}s ago');
  }
}
0
likes
40
pub points
0%
popularity

Publisher

unverified uploader

Calculates how many years, months, days, ... ago a DateTime is.

Repository (GitHub)
View/report issues

License

BSD-2-Clause (LICENSE)

More

Packages that depend on whenwas