This method will tell the length of time from now. Suppose for example if you pass a date to this method it will display the difference if it is in years, months, hours, minutes, or seconds.
var changeddate = moment([2018, 0, 1]).fromNow();
Observe that the date given to the moment is 01/01/2018, the difference till date is 4 months, so the output is given as 4 months ago.
Observe the following example to check the output when no inputs are given to the moment −
var changeddate = moment().fromNow();
Note that in the above shown output, it has the ago keyword appended at the end. In case you do not need it, pass true to fromNow(true) method as shown below −
var changeddate = moment([2015, 10, 01]).fromNow(); var changeddate1 = moment([2015, 10, 01]).fromNow(true);