LoginSignup
6
5

More than 5 years have passed since last update.

javascript:Dateにフォーマッター追加

Posted at

prototype拡張して

Date.prototype.toFormattedString = function(format, weeks) { 
if (weeks == undefined) weeks = ["sun","mon","tue","wed","thu","fri","sat"];
return format.replace(/yyyy/g, this.getFullYear())
.replace(/MM/g, this.getMonth()+1)
.replace(/dd/g, this.getDate())
.replace(/E/g, weeks[this.getDay()]);};

呼び出す

var d = new Date();
console.log(d.toFormattedString("yyyy-MM-dd(E)"))

以上。

6
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
5