I am working with dates stored in MongoDB as UTC using Date(), and the format looks like Mon, 02 Apr 2012 20:16:31 GMT
.
My goal is to calculate the time difference in total seconds between this date and the current time (in UTC).
I attempted the following approach:
now = new Date();
current_date = new Date(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds());
end_date = obj.end_date (Mon, 02 Apr 2012 20:16:35 GMT);
d = new Date(end_date - current_date);
console.log(d.getSeconds());
However, the result shows 22
for seconds, which is incorrect.
This method also seems overly complex. Is there a more efficient way to achieve this either within MongoDB or using JavaScript?
Any suggestions or advice would be greatly appreciated - thank you!