Note that the js timestamp is 13 BITs and the php timestamp is 10 bits. The conversion function is as follows:
Copy codeThe Code is as follows:
Var nowtime = (new Date). getTime ();/* Current timestamp */
/* Conversion time, calculate the difference value */
Function comptime (beginTime, endTime ){
Var secondNum = parseInt (endTime-beginTime * 1000)/1000); // calculate the time stamp difference
If (secondNum> = 0 & secondNum <60 ){
Return secondNum + 'Seconds ago ';
}
Else if (secondNum> = 60 & secondNum <3600 ){
Var nTime = parseInt (secondNum/60 );
Return nTime + 'minute ago ';
}
Else if (secondNum> = 3600 & secondNum <3600*24 ){
Var nTime = parseInt (secondNum/3600 );
Return nTime + 'hour before ';
}
Else {
Var nTime = parseInt (secondNum/86400 );
Return nTime + 'day before ';
}
}
T = comptime ("1324362556", nowtime); // timestamp is the timestamp sent by PHP through ajax.
Alert (t );