Skip to content

Instantly share code, notes, and snippets.

@dannyid
Last active November 21, 2016 06:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dannyid/1bd65ea300bf15026dea to your computer and use it in GitHub Desktop.
Save dannyid/1bd65ea300bf15026dea to your computer and use it in GitHub Desktop.
Spits out a binary representation of hours:minutes:seconds
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