我有这种格式的约会
Fri Mar 22 2013 23:38:20 GMT+0100 (CET)
我必须检测自从日期到现在已经过了多长时间
我可以使用pre javascript和jquery
答案 0 :(得分:1)
您可以尝试this:
function secondsToString(seconds)
{
var numyears = Math.floor(seconds / 31536000);
var numdays = Math.floor((seconds % 31536000) / 86400);
var numhours = Math.floor(((seconds % 31536000) % 86400) / 3600);
var numminutes = Math.floor((((seconds % 31536000) % 86400) % 3600) / 60);
var numseconds = (((seconds % 31536000) % 86400) % 3600) % 60;
return numyears + " years " + numdays + " days " + numhours + " hours " + numminutes + " minutes " + numseconds + " seconds";
}
var t1= Date.parse('Fri Mar 22 2013 23:38:20 GMT+0100 (CET)');
var t2= new Date()
alert(secondsToString((t2-t1)/1000)) //"0 years 0 days 9 hours 39 minutes 40.98599999999715 seconds"