What should be noted here is that the timestamp of js is 13 digits, and the timestamp of php is 10 digits. The conversion function is as follows:
var nowtime = (new Date).getTime();/*Current timestamp*/
/*Convert time and calculate the difference*/
function comptime (beginTime,endTime){
var secondNum = parseInt((endTime-beginTime*1000)/1000);//Calculate timestamp difference
if(secondNum>=0&&secondNum<60){
return secondNum 'Seconds ago';
}
else if (secondNum>=60&&secondNum<3600){
var nTime=parseInt(secondNum/60);
return nTime 'minutes ago';
}
else if (secondNum>=3600&&secondNum<3600*24){
var nTime=parseInt(secondNum/3600);
return nTime 'hours ago';
}
else{
var nTime = parseInt(secondNum/86400);
return nTime 'days ago';
}
}
t = comptime("1324362556",nowtime);//timestamp is PHP through ajax Returned timestamp
alert(t);
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn