Time from X1.0.0+

  1. moment().from(Moment|String|Number|Date|Array);
  2. moment().from(Moment|String|Number|Date|Array, Boolean);

You may want to display a moment in relation to a time other than now. In that case, you can use moment#from.

  1. var a = moment([2007, 0, 28]);
  2. var b = moment([2007, 0, 29]);
  3. a.from(b) // "a day ago"

The first parameter is anything you can pass to moment() or an actual Moment.

  1. var a = moment([2007, 0, 28]);
  2. var b = moment([2007, 0, 29]);
  3. a.from(b); // "a day ago"
  4. a.from([2007, 0, 29]); // "a day ago"
  5. a.from(new Date(2007, 0, 29)); // "a day ago"
  6. a.from("2007-01-29"); // "a day ago"

Like moment#fromNow, passing true as the second parameter returns value without the suffix. This is useful wherever you need to have a human readable length of time.

  1. var start = moment([2007, 0, 5]);
  2. var end = moment([2007, 0, 10]);
  3. end.from(start); // "in 5 days"
  4. end.from(start, true); // "5 days"

From version 2.10.3, if any of the endpoints are invalid the result is thelocalized Invalid date string.