Created
September 30, 2017 12:49
-
-
Save jeffminsungkim/1d1c00b3bafa14a81cbb1972c8e9027e to your computer and use it in GitHub Desktop.
Format JavaScript Date to 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 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