Fetching contributors…
Cannot retrieve contributors at this time
103 lines (91 sloc) 2.34 KB
title version signature
Time to now
moment().toNow(); moment().toNow(Boolean);

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

This is similar to moment.fromNow, but gives the opposite interval: a.fromNow() = - a.toNow().

This is similar to, but is special-cased for the current time. Use, if you want to control the two end points of the interval.

moment([2007, 0, 29]).toNow(); // in 4 years

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

moment([2007, 0, 29]).toNow();     // in 4 years
moment([2007, 0, 29]).toNow(true); // 4 years

The base strings are customized by the current locale.

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

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