Skip to content

How to Convert Minutes to Hours and Minutes, Alternate Method #3285

Answered by sbulatnikov
hakimLyon asked this question in Q&A
Discussion options

You must be logged in to vote

You should do it by yourself, examples below
with additional zeros (digital clock style)

const minutesToHoursExtended = minutes => {
  const hours = minutesToHours(minutes);
  const minutesLeft = minutes - hours * 60;
  const stringifiedHours = String(hours).length === 1 ? `0${hours}` : `${hours}`;
  const stringifiedMinutes =
    String(minutesLeft).length === 1 ? `0${minutesLeft}` : `${minutesLeft}`;
  return `${stringifiedHours}:${stringifiedMinutes}`;
};

console.log(minutesToHoursExtended(175));   // 02:55
console.log(minutesToHoursExtended(120));   // 02:00
console.log(minutesToHoursExtended(59));    // 00:59

or without additional zeros

const minutesToHoursExtendedSimplified = minutes 

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@hakimLyon
Comment options

Answer selected by hakimLyon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants