Last active
August 29, 2015 14:24
-
-
Save mu-777/32ca29c693b6f2ad4dbd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function makeSameDayArr(targetDay, firstDate){ | |
var targetDates = [], | |
targetDate = new Date(firstDate.getFullYear(), | |
firstDate.getMonth(), | |
1.0 + (7-(firstDate.getDay()-targetDay)%7)%7); | |
for(;targetDate.getMonth() == firstDate.getMonth();targetDate.setDate(targetDate.getDate()+7)){ | |
targetDates.push(new Date(targetDate)); | |
} | |
return targetDates; | |
} | |
var days = { 'sun': 0, 'mon': 1, 'tue': 2, 'wed': 3, 'thu': 4, 'fri':5, 'sat':6 }; | |
console.log(makeSameDayArr(days['wed'], new Date(2015, 7-1, 1))); | |
// [ Wed Jul 01 2015 00:00:00 GMT+0900 (東京 (標準時)), | |
// Wed Jul 08 2015 00:00:00 GMT+0900 (東京 (標準時)), | |
// Wed Jul 15 2015 00:00:00 GMT+0900 (東京 (標準時)), | |
// Wed Jul 22 2015 00:00:00 GMT+0900 (東京 (標準時)), | |
// Wed Jul 29 2015 00:00:00 GMT+0900 (東京 (標準時)) ] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment