Created
March 22, 2019 01:30
-
-
Save prof3ssorSt3v3/e8fcd963d6e12b1ec44a7a4ba3936c80 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Lifesaver