将时长与时间差一起使用
你还可以使用 dayjs#diff
的持续时间来获取两个日期时间之间的持续时间。为此,只需将 dayjs#diff
方法传递给 dayjs#duration
,如下所示:
¥You can also use duration with dayjs#diff
to get the duration between two date times. To do so, simply pass the dayjs#diff
method into dayjs#duration
as follows:
var x = dayjs()
var y = dayjs()
var duration = dayjs.duration(x.diff(y))
// returns duration object with the duration between x and y
有关 dayjs#diff
的更多信息,请参见 此处。
¥See here for more information about dayjs#diff
.