我需要能夠從nsdate得到星期幾,我有下面的代碼,它總是返回1.我試圖改變月份,我嘗試了從1到12的所有內容,但是一週的結果總是1。客觀C - 我如何從NSDate獲得工作日?
NSDate *date2 = [[NSDate alloc] initWithString:[NSString stringWithFormat:@"%d-%d-%d", 2010, 6, 1]];
unsigned units2 = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSWeekdayCalendarUnit;
NSCalendar *calendar2 = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *components2 = [calendar2 components:units2 fromDate:date2];
int startWeekDay = [components2 weekday];
[date2 release];
[calendar2 release];
可能的重複[如何使用Cocoa Touch獲取星期幾?](http://stackoverflow.com/questions/4269093/how-do-i-get-the-day-of-the-每週用可可觸摸) – Suhaib 2016-10-05 03:34:32