Created
March 8, 2017 00:50
-
-
Save fredyfx/676d17ac566d02d7b2bb9132bb93acd6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var date = new Date("01/21/2017"); | |
var yyyy = date.getFullYear().toString(); | |
var mm = (date.getMonth()+1).toString(); | |
var dd = date.getDate().toString(); | |
// CONVERT mm AND dd INTO chars | |
var mmChars = mm.split(''); | |
var ddChars = dd.split(''); | |
// CONCAT THE STRINGS IN YYYY-MM-DD FORMAT | |
var datestring = yyyy + '-' + (mmChars[1]?mm:"0"+mmChars[0]) + '-' + (ddChars[1]?dd:"0"+ddChars[0]); | |
console.log("the result is: "); //2017-01-21 | |
console.log(datestring); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment