Skip to content

Instantly share code, notes, and snippets.

@prof3ssorSt3v3
Created March 22, 2019 01:30
Show Gist options
  • Save prof3ssorSt3v3/e8fcd963d6e12b1ec44a7a4ba3936c80 to your computer and use it in GitHub Desktop.
Save prof3ssorSt3v3/e8fcd963d6e12b1ec44a7a4ba3936c80 to your computer and use it in GitHub Desktop.
/**
* Converting seconds into proper time values like a digital clock
* 00:01:03
*/
let timmy = setInterval(showTime, 1000);
let seconds = 3595;
function showTime() {
//update the time as hours, minutes, and seconds 00:00:00
seconds++;
let hours = Math.floor(seconds / 3600);
let mins = Math.floor(seconds / 60) - (hours * 60);
let secs = Math.floor(seconds % 60);
let output = hours.toString().padStart(2, '0') + ':' +
mins.toString().padStart(2, '0') + ':' +
secs.toString().padStart(2, '0');
console.log(output);
}
@cyborgx99
Copy link

Lifesaver

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment