Js processing PHP output timestamp not on the solution
- 2020-03-30 03:24:10
- OfStack
The timestamp passed in by PHP for JS processing is always out of place. The original JS timestamp was 13 bits and contained 3 milliseconds, while PHP only had 10 bits and contained no milliseconds.
var nowtime = (new Date).getTime();
function comptime(beginTime,endTime){
var secondNum = parseInt((endTime-beginTime*1000)/1000);//Calculate the timestamp difference
if(secondNum>=0&&secondNum<60){
return secondNum+' Seconds before ';
}
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 before ';
}
else{
var nTime = parseInt(secondNum/86400);
return nTime+' Days ago, ';
}
}
t = comptime(timestamp,nowtime);//timestamp for PHP through ajax The time stamp returned