Home > Web Front-end > JS Tutorial > body text

Javascript timestamp and PHP timestamp conversion considerations_Basic knowledge

WBOY
Release: 2016-05-16 17:37:24
Original
1062 people have browsed it

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:

Copy code The code 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);
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!