Last active
December 1, 2017 08:17
-
-
Save ayoayco/967f5d083d3ce3a7996cd53c2a5bfe6b to your computer and use it in GitHub Desktop.
Modern JavaScript function for formatting Date to String yyyy-MM-dd
This file contains 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 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