97
rated 0 times
[
101]
[
4]
/ answers: 1 / hits: 58418
/ 7 Years ago, thu, january 26, 2017, 12:00:00
So This is my first time using Moment.js and I encountered the following problem, so I have this following dates:
now: 2017-01-26T14:21:22+0000
expiration: 2017-01-29T17:24:22+0000
What I want to get is:
Day: 3
Hours: 3
Mins: 3
I tried the following code:
const now = moment();
const exp = moment(expire_date);
console.log(expire_date);
days = exp.diff(now, 'days');
hours = exp.diff(now, 'hours') - (days * 24);
minutes = exp.diff(now, 'minutes') - ((days * 1440) + (hours * 24) * 60);
I know I did something wrong (maybe my calculation or I used the wrong method), but I can't figure out what it is.
More From » momentjs