Luckylooke Luckylooke - 1 year ago 106
Javascript Question

Moment.js giving tomorow and yesterday in reverse

My console:

enter image description here

same w/o new Date constructor:

enter image description here

What can be wrong??

PS: it is not project related because I am getting same results in console on

To easily reproduce, go to, open console, put:

moment().calendar('2016-11-27T07:31:29.000+0000'); // expecting "Sunday at 9:58 AM" getting "Tuesday at 9:58 AM"
moment().calendar('2016-11-28T07:31:29.000+0000'); // expecting "Yesterday at 9:58 AM" getting "Tomorrow at 9:58 AM"
moment().calendar('2016-11-29T07:31:29.000+0000'); // this is correct "Today at 9:58 AM"
moment().calendar('2016-11-30T07:31:29.000+0000'); // expecting "Tomorrow at 9:58 AM" getting "Yesterday at 9:58 AM"

Answer Source

In the docs it says:


Calendar time displays time relative to a given referenceTime (defaults to now), but does so slightly differently than moment#fromNow

So the results what you get is correct, because your string time is reference.

For the correct result use:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download