Home  >  Article  >  Web Front-end  >  JS converts seconds into hours, minutes and seconds implementation code_javascript skills

JS converts seconds into hours, minutes and seconds implementation code_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:23:351340browse
Copy code The code is as follows:

function formatSeconds(value) {
var theTime = parseInt(value );// seconds
var theTime1 = 0;// minutes
var theTime2 = 0;// hours
// alert(theTime);
if(theTime > 60) {
theTime1 = parseInt(theTime/60);
theTime = parseInt(theTime`);
// alert(theTime1 "-" theTime);
if(theTime1 > 60) {
theTime2 = parseInt(theTime1/60);
theTime1 = parseInt(theTime1`);
}
}
var result = "" parseInt(theTime) "seconds";
if(theTime1 > ; 0) {
result = "" parseInt(theTime1) "minutes" result;
}
if(theTime2 > 0) {
result = "" parseInt(theTime2) "hour" result ;
}
return result;
}
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