Skip to content

Instantly share code, notes, and snippets.

@ayoayco
Last active December 1, 2017 08:17
Show Gist options
  • Save ayoayco/967f5d083d3ce3a7996cd53c2a5bfe6b to your computer and use it in GitHub Desktop.
Save ayoayco/967f5d083d3ce3a7996cd53c2a5bfe6b to your computer and use it in GitHub Desktop.
Modern JavaScript function for formatting Date to String yyyy-MM-dd
function getFormattedDate(d) {
if(!d){
d = new Date();
}
const transactionDate = [d.getFullYear(), `0${d.getMonth() + 1}`.slice(-2), `0${d.getDate()}`.slice(-2)].join('');
return transactionDate;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment