我使用Date()存儲在MongoDB中的日期,MongoDB使用UTC日期類型,並且字符串看起來像Mon, 02 Apr 2012 20:16:31 GMT
。從JavaScript中的兩個日期獲取差異秒數
我想知道在這段時間和當前時間(UTC)之間的總時間差異。
我已經試過這樣:
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());
這幾秒鐘,這顯然是不正確的顯示22
。
它似乎過於複雜了。也許在MongoDB中有更好的方法,或者在JavaScript中有一個正確的方法來做到這一點?
任何建議將是偉大的 - 謝謝你!