moment().fromNow(); moment().fromNow(Boolean);

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

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

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

moment([2007, 0, 29]).fromNow();     // 4 years ago
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.

Range Key Sample Output
0 to 44 seconds s a few seconds ago
unset ss 44 seconds ago
45 to 89 seconds m a minute ago
90 seconds to 44 minutes mm 2 minutes ago ... 44 minutes ago
45 to 89 minutes h an hour ago
90 minutes to 21 hours hh 2 hours ago ... 21 hours ago
22 to 35 hours d a day ago
36 hours to 25 days dd 2 days ago ... 25 days ago
26 to 45 days M a month ago
45 to 319 days MM 2 months ago ... 10 months ago
320 to 547 days (1.5 years) y a year ago
548 days+ yy 2 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).