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
Release: 2016-05-16 17:21:58
Original
1269 people have browsed it

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

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