Skip to content

Instantly share code, notes, and snippets.

@return-none
Last active December 20, 2015 05:59
Show Gist options
  • Save return-none/6082999 to your computer and use it in GitHub Desktop.
Save return-none/6082999 to your computer and use it in GitHub Desktop.
// formats Date object in format "yyyy-mm-dd"
function format_date(date) {
var day = date.getDate().toString();
var month = (date.getMonth() + 1).toString();
var year = date.getFullYear().toString();
if (day.length === 1) day = "0" + day;
if (month.length === 1) month = "0" + month;
return [day, month, year].join('-');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment