时刻查找两个日期对象之间的差异
我的项目中有两个日期,
let a="30-03-1999"
let b="30-03-2022"
现在我需要找到这两个日期之间的差异,所以首先我通过
let birthdate = moment(a, 'DD-MM-YYYY')
let licenseDate = moment(b, 'DD-MM-YYYY')
//console.log(birthdate,licenseDate) gives me moment object
Object { _isAMomentObject: true, _i: "30-03-1950", _f: "DD-MM-YYYY", _isUTC: false, _pf: {…}, _locale: {…}, _d: Date Thu Mar 30 1950 00:00:00 GMT+0530 (India Standard Time), _isValid: true }
函数将它们转换为 moment 对象
var diff = licenseDate.diff(birthdate, 'years')
运行返回 NaN 的
I have two dates in my project which are
let a="30-03-1999"
let b="30-03-2022"
Now i need to find the difference between these two dates, so first i am converting them to moment object by
let birthdate = moment(a, 'DD-MM-YYYY')
let licenseDate = moment(b, 'DD-MM-YYYY')
//console.log(birthdate,licenseDate) gives me moment object
Object { _isAMomentObject: true, _i: "30-03-1950", _f: "DD-MM-YYYY", _isUTC: false, _pf: {…}, _locale: {…}, _d: Date Thu Mar 30 1950 00:00:00 GMT+0530 (India Standard Time), _isValid: true }
upon running the function
var diff = licenseDate.diff(birthdate, 'years')
it returns NaN
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
DD-MM-YYYY
不是正确的日期格式,您应该尝试使用YYYY-MM-DD
,它会正常工作,并且也可以使用
DD- MM-YYYY
DD-MM-YYYY
is not the correct date format, you should try withYYYY-MM-DD
, It will work fineand It will also with
DD-MM-YYYY