생존기술_IT/JavaScript

[JS] JavaScript로 YYYY-MM-DD 날짜 연월일 가져오기

LeCafeCreme 2021. 9. 8. 14:15

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();

 

 

출처 : https://stackoverflow.com/questions/3066586/get-string-in-yyyymmdd-format-from-js-date-object