Subscribe:

Main Menu

Senin, Oktober 27, 2008

nambah hari pakai javascript

aku juga sempet tersendat di sini juga neh. gimana caranya agar menambah hari pake javascript. dan sama juga, setelah di cari-cari caranya. ada juga script untuk nambah hari :D. scriptnya gini nech



function myDate(year, month, day) {
this.year = year;
this.month = month;
this.day = day;
}

function dateAdd(date, n) {
date.day += n;
while(date.day <=0 || date.day > daysOfMonth(date.year, date.month)) {
if(date.day <= 0){
prevMonth(date);
date.day += daysOfMonth(date.year, date.month);
} else {
date.day -= daysOfMonth(date.year, date.month);
nextMonth(date);
}
}
}






function daysOfMonth(year, month) {
var days = new makeArray(12);

days[1] = 31; days[2] = 28; days[3] = 31;
days[4] = 30; days[5] = 31; days[6] = 30;
days[7] = 31; days[8] = 31; days[9] = 30;
days[10] = 31; days[11] = 30; days[12] = 31;

if(year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
days[2] = 29;

return days[month];
}

function prevMonth(date) {
if(date.month == 1) {
date.year--; date.month = 12;
} else {
date.month--;
}
}

function nextMonth(date) {
if(date.month == 12) {
date.year++; date.month = 1;
} else {
date.month++;
}
}

function makeArray(n) {
this.length = n;
return this;
}




0 komentar: