date object
JS を使用して を 形式の文字列に変換しようとしています。 、、をYYYYMMDD
連結するよりも簡単な方法はありますか?Date.getYear()
Date.getMonth()
Date.getDay()
ベストアンサー1
私がよく使用するコードを変更しました:
Date.prototype.yyyymmdd = function() {
var mm = this.getMonth() + 1; // getMonth() is zero-based
var dd = this.getDate();
return [this.getFullYear(),
(mm>9 ? '' : '0') + mm,
(dd>9 ? '' : '0') + dd
].join('');
};
var date = new Date();
date.yyyymmdd();