Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,900 questions

51,831 answers

573 users

How to convert milliseconds to hours and minutes in TypeScript

1 Answer

0 votes
function convertMsToHourAndMinutes(milliseconds : number) {
    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;

    minutes = +minutes.toString().padStart(2, '0');
    hours = +hours.toString().padStart(2, '0');

    return `${hours}:${minutes}`;
}

console.log(convertMsToHourAndMinutes(98417646)); 
  

  

/*
run:
  
"27:20" 
  
*/

 



answered Mar 20, 2022 by avibootz
...