Created
February 27, 2014 14:18
-
-
Save amontalenti/9250917 to your computer and use it in GitHub Desktop.
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
| function getCurrentDateString() { | |
| // JavaScript Date API does not return zero-padded date strings, so we need this utility | |
| var pad = function(number) { | |
| if (number < 10) { | |
| return '0' + number; | |
| } | |
| return number; | |
| }; | |
| // get the current day and format it as YYYY-MM-DD-HH | |
| var date = new Date(), | |
| dateString = date.getUTCFullYear() + | |
| '-' + pad(date.getUTCMonth() + 1) + | |
| '-' + pad(date.getUTCDate()) + | |
| '-' + pad(date.getUTCHours()); | |
| return dateString; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment