반응형
var startDate = new Date(new Date().getFullYear(), new Date().getMonth() + 1, 1);
var endDate = new Date(new Date().getFullYear(), new Date().getMonth() + 1, 0);

var startOfDay = startOfDay.getFullYear() + "-" + startOfDay.getMonth() + "-" + startOfDay.getDate()
var endOfDay = endOfDay.getFullYear() + "-" + startOfDay.getMonth() + "-" + endOfDay.getDate()

결과 : yyyy-m-d

 

만약 8자리로 쓰고싶으면 아래 _pad 함수에 넣어서 쓰면 됩니다.

var startOfDay = startOfDay.getFullYear() + "-" + _pad(startOfDay.getMonth(),2) + "-" + _pad(startOfDay.getDate(),2);
var endOfDay = endOfDay.getFullYear() + "-" + _pad(startOfDay.getMonth(),2) + "-" + _pad(endOfDay.getDate(),2);

결과 yyyy-mm-dd

function _pad(n, width) {
    n = n + '';
    return n.length >= width ? n : new Array(width - n.length + 1).join('0') + n;
}

+ Recent posts