Last active
November 21, 2016 06:06
-
-
Save dannyid/1bd65ea300bf15026dea to your computer and use it in GitHub Desktop.
Spits out a binary representation of hours:minutes:seconds
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
setInterval(displayTime, 1000); | |
function displayTime() { | |
var date = new Date(); | |
var h = date.getHours().toString(2); | |
var m = date.getMinutes().toString(2); | |
var s = date.getSeconds().toString(2); | |
h = fillStringLength(h, 5, '0'); | |
m = fillStringLength(m, 6, '0'); | |
s = fillStringLength(s, 6, '0'); | |
console.log(h + ':' + m + ':' + s); | |
}; | |
function fillStringLength(string, desiredLength, fillerText) { | |
if (string.length < desiredLength) { | |
string = fillerText+string; | |
return fillStringLength(string, desiredLength, fillerText); | |
} else { | |
return string; | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment