内容来自文档
时差 (毫秒) 1.0.0+
编辑moment().diff(Moment|String|Number|Date|Array); moment().diff(Moment|String|Number|Date|Array, String); moment().diff(Moment|String|Number|Date|Array, String, Boolean);To get the difference in milliseconds, use
moment#difflike you would usemoment#from.var a = moment([2007, 0, 29]); var b = moment([2007, 0, 28]); a.diff(b) // 86400000To get the difference in another unit of measurement, pass that measurement as the second argument.
var a = moment([2007, 0, 29]); var b = moment([2007, 0, 28]); a.diff(b, 'days') // 1The supported measurements are years, months, weeks, days, hours, minutes, and seconds. For ease of development, the singular forms are supported as of 2.0.0. Units of measurement other than milliseconds are available in version 1.1.1.
By default,
moment#diffwill return number rounded down. If you want the floating point number, passtrueas the third argument. Before 2.0.0,moment#diffreturned rounded number, not a rounded down number.var a = moment([2008, 6]); var b = moment([2007, 0]); a.diff(b, 'years'); // 1 a.diff(b, 'years', true); // 1.5
998

被折叠的 条评论
为什么被折叠?



