2010-03-08 61 views

回答

2

我知道,我給沒有優化,但它只是給你一個方法來探索。 您可以使用NSCalendar和這樣的NSDateComponents:

// Date of today 
NSDate *today = [NSDate date]; 
// init the gregorian calendar 
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; 
// Retrieve the NSDateComponents for the current date 
NSDateComponents *weekdayComponents = [gregorian components:(NSDayCalendarUnit | NSWeekdayCalendarUnit) fromDate:today]; 
// Number of the day in the week (e.g 2 = Monday) 
NSInteger weekday = [weekdayComponents weekday]; 

(見Calendars, Date Components, and Calendar Units

從那裏,你在第一次約會開始,你重複這每一天,直到你的結束日期和使用平日你可以確定一天是否在週末。 (我重複說,這不是優化,但它只是一個軌道)

+0

謝謝雅尼克。 如果有人知道比列舉每個nsdate實例來檢查星期幾值更有效的方法,那麼我會很感激它。 – 2010-03-15 14:39:56

相關問題