Created
February 7, 2015 12:32
-
-
Save bulatie/cf52bd513d0f21634ff7 to your computer and use it in GitHub Desktop.
24 hours time format
This file contains hidden or 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
//pads n with zeros on the left, | |
//digits is minimum length of output | |
//zeroPad(3, 5); returns "005" | |
//zeroPad(2, 500); returns "500" | |
zeroPad: function(digits, n) { | |
n = n.toString(); | |
while(n.length < digits) | |
n = '0' + n; | |
return n; | |
}, | |
//it is almost 8 o'clock PM here | |
//timeString(new Date); returns "19:49" | |
timeString: function(date) { | |
var minutes = date.getMinutes().toString(); | |
var hours = date.getHours().toString(); | |
return this.zeroPad(2, hours) + ":" + this.zeroPad(2, minutes); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment