Skip to content

Instantly share code, notes, and snippets.

@amontalenti
Created February 27, 2014 14:18
Show Gist options
  • Select an option

  • Save amontalenti/9250917 to your computer and use it in GitHub Desktop.

Select an option

Save amontalenti/9250917 to your computer and use it in GitHub Desktop.
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