그래고리력에 알고리즘에 기반 윤년 체크
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);
'Html-JavaScript' 카테고리의 다른 글
[JavaScript] 쿠키값으로 팝업제어 (0) | 2007.01.09 |
---|---|
[알고리즘] 윤년이야기 (0) | 2007.01.09 |
숫자 데이터중에서 Comma(,) 를 전부 없애는 함수 (0) | 2007.01.09 |
소수점 자리가 있는 숫자 중에서 Comma(,)를 붙이는 함수 (0) | 2007.01.09 |
[JavaScript] 문자열(한글 2바이트) 길이 체크 (0) | 2007.01.09 |