[편집 : 정말 미안, @ndix하지만, 이전 코드 (삭제)를 완전히 결함이있다. 네거티브는 작동하지 않습니다. 사용]
timeDirectionIndex = 0;//initial for today or future
daysToAdd = -15;//you can make this zero or any positive or negative integer
d = new Date(Date(0));
var weekday=new Array(7);
if (daysToAdd < 0) {timeDirectionIndex = 1;}
//if time is reversed, uses second column
weekday[0]=["Sunday","Saturday"][timeDirectionIndex];
weekday[1]=["Monday","Friday"][timeDirectionIndex];
weekday[2]=["Tuesday","Thursday"][timeDirectionIndex];
weekday[3]=["Wednesday","Wednesday"][timeDirectionIndex];
weekday[4]=["Thursday","Tuesday"][timeDirectionIndex];
weekday[5]=["Friday","Monday"][timeDirectionIndex];
weekday[6]=["Saturday","Sunday"][timeDirectionIndex];
//Math.abs makes it always positive; we rely on order of array now
if (daysToAdd < 0) {
wd=weekday[ (Math.abs(daysToAdd) + 3 + (3 - d.getDay()) )%7 ];
} else {
wd=weekday[ (Math.abs(daysToAdd) + ( d.getDay() ))%7 ];
}
alert(wd);
아래의 코드는 [이전 코드는 작동하지 않았다 ]
당신이 날짜 개체를 사용하는 경우 어떻게 6보다 클 거라고 할 수 있습니까? – fabianmoronzirfas