moment().diff returns negative value

Created on 4 Apr 2012  路  1Comment  路  Source: moment/moment

//Wed, 04 Apr 2012 21:09:16 GMT to = moment.utc().add('m', 60).toDate(); seconds = moment.diff(to, 'seconds');
I'm trying to get the seconds from the current time in UTC and another date that is set in UTC.

I'm using moment.diff- the above code returns a negative value of -3600 instead of 3600.

Is this the correct way to do this? Shouldn't the negative only be if the date has passed?

Bug

Most helpful comment

That should be clarified in the docs.

If the moment is earlier than the one you are diffing, it should be negative. If it is after the one you are diffing, it will be positive.

Think of it this way...

var a = moment(),
    b = moment().add('hours', 1);
a.diff(b); // a - b
b.diff(a); // b - a

>All comments

That should be clarified in the docs.

If the moment is earlier than the one you are diffing, it should be negative. If it is after the one you are diffing, it will be positive.

Think of it this way...

var a = moment(),
    b = moment().add('hours', 1);
a.diff(b); // a - b
b.diff(a); // b - a
Was this page helpful?
5 / 5 - 1 ratings

Related issues

nikocraft picture nikocraft  路  3Comments

dogukankotan picture dogukankotan  路  3Comments

RobinvanderVliet picture RobinvanderVliet  路  3Comments

BCup picture BCup  路  3Comments

Shoroh picture Shoroh  路  3Comments