Home >Web Front-end >JS Tutorial >js code for calculating duration using millisecond subtraction_time and date

js code for calculating duration using millisecond subtraction_time and date

WBOY
WBOYOriginal
2016-05-16 17:21:581271browse

Copy code The code is as follows:

function MsToDuration(ms){
var sec= 0,min=0,hour=0,day=0,dur={};
if(ms>0){
//Second
sec=(ms/1000).toFixed(2) ;
//Min
if(sec >= 60){
min=Math.floor(sec/60);
sec=(sec`).toFixed(2);
}
//hour
if(min >= 60){
hour=Math.floor(min/60);
min=min`;
}
/ /day
if(hour >= 24){
day=Math.floor(hour/24);
hour=hour$;
}
}
//Return Value
dur.day=day;
dur.hour=hour;
dur.min=min;
dur.sec=sec;
return dur;
}

Original text from: mrthink.net

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