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

js processing php output timestamp does not match the solution_javascript skills

WBOY
Release: 2016-05-16 16:43:44
Original
1547 people have browsed it

I wonder why the timestamp passed from PHP to JS for processing is always mismatched. It turns out that the JS timestamp is 13 digits, including 3 digits of milliseconds, while PHP only has 10 digits that do not include milliseconds.

var nowtime = (new Date).getTime();/*当前时间戳*/ 
/*转换时间,计算差值*/ 
function comptime(beginTime,endTime){ 
var secondNum = parseInt((endTime-beginTime*1000)/1000);//计算时间戳差值 

if(secondNum>=0&&secondNum<60){ 
return secondNum+'秒前'; 
} 
else if (secondNum>=60&&secondNum<3600){ 
var nTime=parseInt(secondNum/60); 
return nTime+'分钟前'; 
} 
else if (secondNum>=3600&&secondNum<3600*24){ 
var nTime=parseInt(secondNum/3600); 
return nTime+'小时前'; 
} 
else{ 
var nTime = parseInt(secondNum/86400); 
return nTime+'天前'; 
} 
} 
t = comptime(timestamp,nowtime);//timestamp为PHP通过ajax回传的时间戳
Copy after login
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!