我想计算今天和给定日期之间的天数,并检查距离今天还有多少天或从今天过去多少天。
var today = new Date();
var date_to_reply = new Date('2012-10-15');
var timeinmilisec = today.getTime() - date_to_reply.getTime();
console.log( Math.floor(timeinmilisec / (1000 * 60 * 60 * 24)) );
这给了我5作为答案,但是由于 date_to_reply 从今天起已经过去了5 天,我应该如何得到(-5) ?
这是计算任何给定日期的正确方法吗?
问候