Javascript 如何获取json日期经过的时间?

Javascript 如何获取json日期经过的时间?,javascript,json,parsing,datetime,Javascript,Json,Parsing,Datetime,我正在使用jquery ajax($.ajax)方法从c#webmethod获取一个json对象 new Date(parseInt(json.d.Date.replace("/Date(", "").replace(")/",""), 10)) 最后的日期是这样的 日期{Wed Feb 15 2012 16:48:12 GMT+0000(GMT标准时间)} 我想在javascript中查找从这个日期时间到当前时间所经过的时间,但我不确定如何做,因为解析的日期看起来像字符串而不是日期 有人能帮

我正在使用jquery ajax($.ajax)方法从c#webmethod获取一个json对象

new Date(parseInt(json.d.Date.replace("/Date(", "").replace(")/",""), 10))
最后的日期是这样的

日期{Wed Feb 15 2012 16:48:12 GMT+0000(GMT标准时间)}

我想在javascript中查找从这个日期时间到当前时间所经过的时间,但我不确定如何做,因为解析的日期看起来像字符串而不是日期

有人能帮忙吗

谢谢

您可以:

//timestamp from json
var startTime = parseInt(json.d.Date.replace("/Date(", "").replace(")/",""), 10))
//current timestamp
var endTime = new Date().getTime();
//difference in milliseconds
var diff = endTime - startTime;

好吧,如果是在同一天,我可以做var endTime=new Date().getTime();如果是不同的一天,我应该如何处理它?@kranthi
getTime()
获取unix时代以来的毫秒数,而不是一天中的时间。因此,
diff
是从一个时间点到另一个时间点的毫秒差。不管它是在另一天还是在另一年——它只是毫秒数
var json = {d:{Date:"/Date(1329324492302)/"}};

var date1 = new Date(parseInt(json.d.Date.replace("/Date(", "").replace(")/",""), 10));
var date2 = new Date();

var diff = (date2-date1);  // 

var hours = Math.floor( diff / 3600000);
var minutes = Math.floor( (diff % 3600000) / 60000);
var seconds = Math.floor( ((diff % 3600000) % 60000) / 1000);

console.log(" elapsed " + hours + ":" + minutes + ":" + seconds );