KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Terminal output: Now: { _d: Sat Jan 13 2018 02:39:25 GMT-0400 (AST), _isUTC: false, _a: null, _lang: false } Expiration Date: { _d: Wed Feb 13 2013 02:00:15 GMT-0400 (AST), _isUTC: false, _a: null, _lang: false } Difference between Now and Expiration Date: NaN Code: console.log('Difference between Now and Expiration Date:', now.diff(expDate, 'months', true)); moment.js source: diff : function (input, val, asFloat) { var inputMoment = this._isUTC ? moment(input).utc() : moment(input).local(), zoneDiff = (this.zone() - inputMoment.zone()) * 6e4, diff = this._d - inputMoment._d - zoneDiff, year = this.year() - inputMoment.year(), month = this.month() - inputMoment.month(), date = this.date() - inputMoment.date(), output; if (val === 'months') { output = year * 12 + month + date / 30; } else if (val === 'years') { output = year + (month + date / 30) / 12; } else { output = val === 'seconds' ? diff / 1e3 : // 1000 val === 'minutes' ? diff / 6e4 : // 1000 * 60 val === 'hours' ? diff / 36e5 : // 1000 * 60 * 60 val === 'days' ? diff / 864e5 : // 1000 * 60 * 60 * 24 val === 'weeks' ? diff / 6048e5 : // 1000 * 60 * 60 * 24 * 7 diff; } return asFloat ? output : round(output); }
Tags (comma-separated)
Save Edits
Cancel