Skip to content

Instantly share code, notes, and snippets.

@jeffminsungkim
Created September 30, 2017 12:49
Show Gist options
  • Save jeffminsungkim/1d1c00b3bafa14a81cbb1972c8e9027e to your computer and use it in GitHub Desktop.
Save jeffminsungkim/1d1c00b3bafa14a81cbb1972c8e9027e to your computer and use it in GitHub Desktop.
Format JavaScript Date to yyyy-mm-dd
function formatDate(date){
var d = new Date(date);
var month = '' + (d.getMonth() + 1);
var day = '' + d.getDate();
var year = d.getFullYear();
if (month.length < 2)
month = '0' + month;
if (day.length < 2)
day = '0' + day;
return [year, month, day].join('-');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment