반응형
function 날짜(vDate)
{
	var vPrevDate;
	var vNowDate = new Date().getFullYear()+"-"+_pad(new Date().getMonth() + 1, 2)+"-"+_pad(new Date().getDate(), 2);
	var vResult;

	var d = new Date();
	var dayOfMonth = d.getDate();

	if(vDate == "now")
	{
		vPrevDate = vNowDate;
	}
	else if(vDate == "1week")
	{
		d.setDate(dayOfMonth - 7);
		vPrevDate = d.getFullYear()+"-"+_pad(d.getMonth() + 1,2)+"-"+_pad(d.getDate(),2);
	}
	else if(vDate == "2week")
	{
		d.setDate(dayOfMonth - 14);
		vPrevDate = d.getFullYear()+"-"+_pad(d.getMonth() + 1,2)+"-"+_pad(d.getDate(),2);
	}
	else if(vDate == "3week")
	{
		d.setDate(dayOfMonth - 21);
		vPrevDate = d.getFullYear()+"-"+_pad(d.getMonth() + 1,2)+"-"+_pad(d.getDate(),2);
	}
}

_pad 함수

//숫자 width만큼 앞에 0 붙혀주는 함수 EX) widht = 2일떄 1은 01로 찍힘
function _pad(n, width) {
    n = n + '';
    return n.length >= width ? n : new Array(width - n.length + 1).join('0') + n;
}​

+ Recent posts