Skip to content

Instantly share code, notes, and snippets.

@horitaku1124
Created July 8, 2013 01:56
Show Gist options
  • Save horitaku1124/5945723 to your computer and use it in GitHub Desktop.
Save horitaku1124/5945723 to your computer and use it in GitHub Desktop.
JavaScriptで日付フォーマット
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