Time from now1.0.0+

  1. moment().fromNow();
  2. moment().fromNow(Boolean);

A common way of displaying time is handled by moment#fromNow. This is sometimes called timeago or relative time.

  1. moment([2007, 0, 29]).fromNow(); // 4 years ago

If you pass true, you can get the value without the suffix.

  1. moment([2007, 0, 29]).fromNow(); // 4 years ago
  2. moment([2007, 0, 29]).fromNow(true); // 4 years

The base strings are customized by the current locale. Time is rounded to the nearest second.

The breakdown of which string is displayed for each length of time is outlined in the table below.

RangeKeySample Output
0 to 44 secondssa few seconds ago
unsetss44 seconds ago
45 to 89 secondsma minute ago
90 seconds to 44 minutesmm2 minutes ago … 44 minutes ago
45 to 89 minuteshan hour ago
90 minutes to 21 hours hh2 hours ago … 21 hours ago
22 to 35 hoursda day ago
36 hours to 25 daysdd2 days ago … 25 days ago
26 to 45 daysMa month ago
45 to 319 daysMM2 months ago … 10 months ago
320 to 547 days (1.5 years)ya year ago
548 days+yy2 years ago … 20 years ago

Note: From version 2.10.3, if the target moment object is invalid the result is the localized Invalid date string.

Note: The ss key was added in 2.18.0. It is an optional threshold. It will never display UNLESS the user manually sets the ss threshold. Until the ss threshold is set, it defaults to the value of the s threshold minus 1 (so, invisible to the user).