0

I am currently using an API system to return the amount of time that someone has beaten a certain game in Hypixel (Minecraft). This API system returns the time in seconds and it would be much more convenient for it to be in the HH:MM:SS format. Based on some math I have come up with this:

const player = {
  stats: {
    arcade: {
      zombies: {
        overall: {
          fastestRound30: 2214
        }
      }
    }
  }
}

function zombieMath() {

  seconds = player.stats.arcade.zombies.overall.fastestRound30
  splice = seconds / 3600
  full_hours = Math.floor(splice)
  minutes = seconds - full_hours * 60
  full_minutes = Math.floor(minutes)
  remaining_seconds = minutes - full_minutes * 60

  return `${full_hours}:${full_minutes}:${remaining_seconds}`
}

console.log(zombieMath())

I don't fully understand this math, but it has to do with splicing the amount of full hours and minutes and multiply the rest with the remaining seconds. Although the console says something else : Fastest Round 30: 0:2152:-126968

How would I fix this problem? For reference I was trying to output 2,214 to HH:MM:SS format which is just under 37 minutes

Phil
  • 141,914
  • 21
  • 225
  • 223

0 Answers0