duration(x.diff(y))


var duration = moment.duration(x.diff(y))

可以将时长与 moment#diff 一起使用,以获取两个时刻之间的时长。 为此,只需将 moment#diff 方法传给 moment#duration,如下所示:

  var x = new moment()
  var y = new moment()
  var duration = moment.duration(x.diff(y))
  // 返回时长对象,其时长在 x 和 y 之间。

参阅此处以获取有关 moment#diff 的更多信息。

var duration = moment.duration(x.diff(y))

You can also use duration with moment#diff to get the duration between two moments. To do so, simply pass the moment#diff method into moment#duration as follows:

  var x = new moment()
  var y = new moment()
  var duration = moment.duration(x.diff(y))
  // returns duration object with the duration between x and y

See here for more information about moment#diff.