【发布时间】:2012-04-03 15:08:39
【问题描述】:
我使用 Date() 将日期存储在 MongoDB 中,MongoDB 使用 UTC 它是日期类型,并且字符串看起来像 Mon, 02 Apr 2012 20:16:31 GMT。
我想获取此时间与当前时间(以 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 中有正确的方法来做到这一点?
任何建议都会很棒 - 谢谢!
【问题讨论】:
标签: javascript mongodb