Reputation: 6124
I am writing a simple script which would output duration of time from specific time. I am using moment
and moment-duration-format
library
var timeStart = moment('2017-01-29T12:00:00Z'),
timeNow = moment();
var timeDuration = function(timeStart, timeNow) {
return moment.duration(timeStart.unix - timeNow.unix()).format('H:m');
};
console.log(timeDuration(timeStart, timeNow));
Can somebody help me out with this? I don't know do I need to work with unix or iso or something else. And don't know if I need to subtract time or not.
Upvotes: 1
Views: 125
Reputation: 2049
You will want the return to look like this:
return moment.duration((timeNow.unix() - timeStart.unix()) * 1000 ).format('h:mm:ss');
unix time is in seconds and duration wants ms.
Upvotes: 1