How to compare two dates in moment.js

I am using moment.js in my application, I pass my date in a particular format to moment.js and it compares it with the system time and give me the pretty time format, like this:

moment(time, "YYYY-MM-DD HH:mm:ss.SSSSSS").fromNow();

Here the time is given by me as a timestamp in the specified format.

My problem is that fromNow() function takes the system date and not the server date. So, if a user uses his phone with 5 min delay time in his system he will get 4 min ago as the latest updated cards.

I want to compare "time" that I pass with the server time, that also will be passed by me.

You could pass in 2 dates from your server: the existing timestamp, and the server's "now" timestamp.

Then (assuming your server passes in its timestamp in the same format) you can use .from() instead of .fromNow() do:

moment(time, "YYYY-MM-DD HH:mm:ss.SSSSSS").from(serverTime, "YYYY-MM-DD HH:mm:ss.SSSSSS");

If this is the only thing you're using the timestamp for, you could just have the server calculate & return the delta directly (let's call it serverDeltaMs) & format that using moment.duration(serverDeltaMs).humanize().