2011-06-03 60 views

回答

0

https://discussions.apple.com/thread/1700102?start=0&tstart=0和蘋果NSCalendar參考:

如何使用這樣的事情 -

NSDateComponents *comps = [[NSDateComponents alloc] init]; 
[comps setYear:1965]; // Year of the calendar month 
[comps setMonth:1]; // Month 
[comps setDay:6]; // Any day 
NSDate *date = [gregorian dateFromComponents:comps]; 
[comps release]; 

然後,一旦你的NSDate的,這樣做:

NSDate * testDate = [NSDate date]; 
NSString * weekdayString = [testDate descriptionWithCalendarFormat:@"%A" timeZone:nil 
locale:[[NSUserDefaults standardUserDefaults] dictionaryRepresentation]]; 
NSLog(@"Day of the week: %@", weekdayString); 

// weekdayString should look like "Monday", etc. 

所以,你可以循環通過月的日子unti升;

[weekdayString isEqualToString:@"Monday"] // or your desired day 

然後只需添加7天即可獲得其他4個左右的日期。

這可能不是最漂亮的解決方案,但它應該工作。

相關問題