Negative value for moment.diff

Viewed 244

I am getting negative value for moment().diff. I want to get number of seconds between now and past.

var now = moment();
var past = moment("2021-03-23T09:38:05Z"); //past time
var timeLapsed= now.diff(past);
Logger.debug(timeLapsed) //-3219879 

I have searched a lot and could not find any solution. Help will be appreciated.

1 Answers

I do not have enough reputation points to give a simple comment, I have to go through the answer. Sorry! But, I just wanted to say that I reproduced exactly the same code as it is in the question except that with React.js instead of Angular, and instead of Logger I used console.log and the moment.js gave me positive number. Like this:

var now = moment();
var past = moment("2021-03-23T09:38:05Z");
var timeLapsed= now.diff(past);
console.log(timeLapsed) // 765040
Related