わかりました、ここに可能な未テストの解決策があります
date1 = new Date("2012-02-10");
date2 = new Date("2012-03-10");
daysInBetween = (date2.getTime() - date1.getTime())/1000/3600/24;
dayOfTheWeek1 = date1.getDay();
weeks = parseInt(daysInBetween/7, 10);
extraDays = daysInBetween%7;
あなたにはweeks + 1
何日もありますdayOfWeek1 ... dayOfWeek1 + (6 - extraDays)
あなたにはweeks + 1 + extraDays
何日もありますdayOfWeek1 + (6 - extraDays) ... dayOfWeek1 + 6
dayOfWeek1 === 6
その場合、私はそれを想定していることを考慮してくださいdayOfWeek1 + 1 === 0
。
編集:
もう少しコード:
var days = {};
var dayOfTheWeekEnd = dayOfTheWeek1 + 6 - extraDays; // no imagination for names...
if (dayOfTheWeekEnd < 6) {
if (0 >= dayOfTheWeek1 && 0 <= dayOfTheWeekEnd) {
days.sunday = weeks + 1;
} else {
days.sunday = weeks + 1 + extraDays;
}
// etc for the other days, a for loog with an i instead of the 0 would be better.
} else {
// I have to go the school! I'll edit it later.
// The idea is that you have to take dayOfTheWeekEnd back to the 0-6 range
// and check if its after dayOfWeek1 or before dayOfTheWeekEnd, then days.sunday=weeks+1.
}