Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

from milliseconds to hours in js

function msToTime(duration) {
  var milliseconds = parseInt((duration % 1000) / 100),
    seconds = Math.floor((duration / 1000) % 60),
    minutes = Math.floor((duration / (1000 * 60)) % 60),
    hours = Math.floor((duration / (1000 * 60 * 60)) % 24);

  hours = (hours < 10) ? "0" + hours : hours;
  minutes = (minutes < 10) ? "0" + minutes : minutes;
  seconds = (seconds < 10) ? "0" + seconds : seconds;

  return hours + ":" + minutes + ":" + seconds + "." + milliseconds;
}
console.log(msToTime(300000))
Comment

convert milliseconds to minutes and seconds javascript

const millisToMinutesAndSeconds = (millis) => {
    var minutes = Math.floor(millis / 60000);
    var seconds = ((millis % 60000) / 1000).toFixed(0);
	//ES6 interpolated literals/template literals 
  	//If seconds is less than 10 put a zero in front.
    return `${minutes}:${(seconds < 10 ? "0" : "")}${seconds}`;
}
    
Comment

PREVIOUS NEXT
Code Example
Javascript :: syntax jquery 
Javascript :: ts-node dotenv 
Javascript :: z index style javascript 
Javascript :: get window width jquery 
Javascript :: regex special characters javascript 
Javascript :: how to reset checkbox jquery 
Javascript :: delete with unlinksync node 
Javascript :: jquery remove element by id 
Javascript :: hash change listener js 
Javascript :: jquery onscroll sticky header 
Javascript :: javascript regex remove numbers 
Javascript :: strike react native 
Javascript :: javascript get random floating number 
Javascript :: js root url 
Javascript :: las element of object 
Javascript :: Your global Angular CLI version is greater than your local version 
Javascript :: javascript find shortest word in string 
Javascript :: javascript change attribute 
Javascript :: chai expect async throw 
Javascript :: js string limit length 
Javascript :: css customize console.log 
Javascript :: mongoose model find all documents with ids in array 
Javascript :: internal/modules/cjs/loader.js:905 throw err; 
Javascript :: roman numeral converter + javascript 
Javascript :: document on click dynamic element 
Javascript :: email regex specific domain simple 
Javascript :: react native status bar color 
Javascript :: jest timeout 
Javascript :: js append element to body 
Javascript :: es6 add and remove class 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =