Skip to main content
Version: 2.2.0

Relative Duration

warning

Relative durations are rather inaccurate for countdown/timer applications. Use precise duration for more accuracy and flexibility.

Usage

final yesterday = Moment.now() - const Duration(days: 1);
yesterday.fromNow(); // a day ago

final add5sec = Moment.now().add(const Duration(seconds: 5));
add5sec.fromNow(dropPrefixOrSuffix: true); // a few seconds

See abbreviation options

Threshold

Relative durations' output will follow the table below.

Threshold (up to)Text to be displayed
45 secondsa few seconds
90 secondsa minute
45 minutesn minutes
90 minutesan hour
22 hoursn hours
36 hoursa day
26 daysn days
45 daysa month
320 daysn months
548 daysa year
-n year

Thus,

final x = Moment.now() - const Duration(days: 547)
+ fromNow(); // a year ago