let today = new Date();
let year = today.getFullYear(); // 년도
let month = leadingZeros((today.getMonth() + 1),2); // 월
let date = today.getDate(); // 날짜
let now = year+"-"+month+"-"+date;
// 월 앞에 0 붙이기
function leadingZeros(n, digits) {
var zero = '';
n = n.toString();
if (n.length < digits) {
for (i = 0; i < digits - n.length; i++)
zero += '0';
}
return zero + n;
}
==> 한번에 이렇게 해도 됨
function getRecentDate(){
var dt = new Date();
var recentYear = dt.getFullYear();
var recentMonth = dt.getMonth() + 1;
var recentDay = dt.getDate();
if(recentMonth < 10) recentMonth = "0" + recentMonth;
if(recentDay < 10) recentDay = "0" + recentDay;
return recentYear + "-" + recentMonth + "-" + recentDay;
}