본문 바로가기

JSP/JSP

[JSP] 연월 계산

반응형

  • 현재부터 12개월 기간의 연월 계산
function monthChk(){

	var today = new Date(); //객체 생성
	var year = today.getFullYear(); //현재 해
	var month = today.getMonth() + 1; //현재 월 0~11 +1

	var p1  = year+""+month;  //'0'이 붙지않는 숫자의 경우 숫자간의 합산문제 발생 -> 문자화 +""+를  추가
	var p2  = year+""+month_calc(month+1);
	var p3  = year+""+month_calc(month+2);
	var p4  = year+""+month_calc(month+3);
	var p5  = year+""+month_calc(month+4);
	var p6  = year+""+month_calc(month+5);
	var p7  = year+""+month_calc(month+6);
	var p8  = year+""+month_calc(month+7);
	var p9  = year+""+month_calc(month+8);
	var p10  = year+""+month_calc(month+9);
	var p11  = year+""+month_calc(month+10); 
	var p12  = year+""+month_calc(month+11); 
}


function month_calc(n){
    m = n%12  //12로 나눈 나머지
    if(m < 10)
        m = m < 10 ? '0' + m : m;  //10보다 작을 경우 앞에 '0'을 추가
    
    return m;
}

 

 

 

 

반응형