Maximum2.7.0+

  1. moment.max(Moment[,Moment...]);
  2. moment.max(Moment[]);

Returns the maximum (most distant future) of the given moment instances.

For example:

  1. var a = moment().subtract(1, 'day');
  2. var b = moment().add(1, 'day');
  3. moment.max(a, b); // b
  4. var friends = fetchFriends(); /* [{name: 'Dan', birthday: '11.12.1977'}, {name: 'Mary', birthday: '11.12.1986'}, {name: 'Stephan', birthday: '11.01.1993'}]*/
  5. var friendsBirthDays = friends.map(function(friend){
  6. return moment(friend.birthday, 'DD.MM.YYYY');
  7. });
  8. moment.max(friendsBirthDays); // '11.01.1993'

With no arguments the function returns a moment instance with the current time.

From version 2.10.5, if an invalid moment is one of the arguments, the resultis an invalid moment.

  1. moment.max(moment(), moment.invalid()).isValid() === false
  2. moment.max(moment.invalid(), moment()).isValid() === false
  3. moment.max([moment(), moment.invalid()]).isValid() === false
  4. moment.max([moment.invalid(), moment()]).isValid() === false