Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript convert milliseconds to hh mm ss

var result = Math.floor(myDuration/(1000*60*60)) + ":" + Math.floor(myDuration/(1000*60))%60 + ":" + Math.floor(myDuration/1000)%60;
Comment

Convert milliseconds to hh:mm:ss javascript

function padTo2Digits(num) {
  return num.toString().padStart(2, '0');
}

function convertMsToHM(milliseconds) {
  let seconds = Math.floor(milliseconds / 1000);
  let minutes = Math.floor(seconds / 60);
  let hours = Math.floor(minutes / 60);
  seconds = seconds % 60;
  minutes = seconds >= 30 ? minutes + 1 : minutes;
  minutes = minutes % 60;
  hours = hours % 24;
  return `${padTo2Digits(hours)}:${padTo2Digits(minutes)}`;
}

console.log(convertMsToHM(54000000)); //  15:00 (15 hours)
console.log(convertMsToHM(86400000)); //  00:00 (24 hours)
console.log(convertMsToHM(36900000)); //  10:15 (10 hours, 15 minutes)
console.log(convertMsToHM(15335000)); //  04:16 (4 hours, 15 minutes, 35 seconds)
console.log(convertMsToHM(130531000)); // 36:16 (36 hours 15 minutes 31 seconds)
Comment

PREVIOUS NEXT
Code Example
Javascript :: select2 placeholder 
Javascript :: javascript replace newline with br 
Javascript :: number of properties in object javascript 
Javascript :: disable inputetext in react native 
Javascript :: reload page jquery timer 
Javascript :: javascript sleep for 1 second 
Javascript :: javascript get element by class name 
Javascript :: chartjs bar chart hover color 
Javascript :: settimeout en javascript 
Javascript :: how to color console.log 
Javascript :: how to remove item from asyncstorage 
Javascript :: jquery ajax basic authentication 
Javascript :: javascript int to float 
Javascript :: Drupal 8 get page node current path 
Javascript :: disable right click javascript 
Javascript :: install latest npm for react 
Javascript :: return json with jango 
Javascript :: jquery close bootstrap model 
Javascript :: document ready javascript vanilla 
Javascript :: react native view background transparency 
Javascript :: javascript current date add 30 days 
Javascript :: jquery script tag source google 
Javascript :: math random equitative js 
Javascript :: Appium click on element Javascript 
Javascript :: async iife 
Javascript :: how to check if selector exists or is present puppeteer 
Javascript :: how to select html body in javascript 
Javascript :: javascript find file extension from string 
Javascript :: expo ap loading 
Javascript :: jquery body class add 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =