나는 다음 주일의 날짜를 결정하는 JavaScript 함수를 가지고 있습니다. 일요일을 제외한 모든 날 동안 작동합니다.자바 스크립트 날짜, 일요일
For Sunday:
Sun May 25 2014
Sun Jun 08 2014
Sun Jun 22 2014
For Saturday:
Sat May 24 2014
Sat May 31 2014
Sat Jun 07 2014
Sat Jun 14 2014
jsfiddle! 당신이
getDatesByweekDay(0);
를 호출 할 때
function getDatesByweekDay(weekday){
var startdate = new Date();
var date2 = new Date();
lastday = new Date(date2.setDate(date2.getDate() + 28 + weekday - date2.getDay()));
var dates = Array();
var x = 0;
do {
startdate = new Date(startdate.setDate(startdate.getDate() + 7 + weekday - startdate.getDay()));
console.log(startdate);
var date = new Date();
var curr_date = startdate.getDate();
var curr_month = startdate.getMonth() + 1;
var curr_year = startdate.getFullYear();
var formattedDate = curr_year + "-" + curr_month + "-" + curr_date;
dates[x] = formattedDate;
x++;
} while(lastday > startdate);
return dates;
}
getDatesByweekDay(6);
일요일을 건너 뛰는 경우 일요일을 건너 뛰고 있습니다 – AlienWebguy
일요일 만 반환하는 경우 날짜와 시간이 일치하지 않습니다 – PiraTa
일요일은 7 대신 0을 사용하십시오. –