그래고리력에 알고리즘에 기반 윤년 체크

function getLastDay(solar_date)
{
var MonthTable = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
if (((solar_date.getYear() % 4 == 0) && (solar_date.getYear() % 100 != 0)) || (solar_date.getYear()% 400 == 0))
MonthTable[1] = 29;
else
MonthTable[1] = 28;
return MonthTable[solar_date.getMonth()];
}

//사용법
// 예로 2004년 2월의 마지막 날이 몇일인지 알고 싶으면

var nowDate = new Date();

nowDate.setYear( 2000);
nowDate.setMonth(2-1); // 월은 0=1월, 1=2월... 11=12월

nowDate.date= getLastDay(nowDate);

+ Recent posts