Created
July 8, 2013 01:56
-
-
Save horitaku1124/5945723 to your computer and use it in GitHub Desktop.
JavaScriptで日付フォーマット
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
Date.prototype.format = function(str) { | |
var y = this.getFullYear(); | |
var m = this.getMonth() + 1; | |
var d = this.getDate(); | |
m = (m < 10 ? "0" : "") + m; | |
d = (d < 10 ? "0" : "") + d; | |
return str.replace(/Y/g, y).replace(/m/g, m).replace(/d/g, d); | |
}; | |
console.log(new Date().format("Y-m-d")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment