我正在尝试查找日期是否为星期一。
为此,我以这种方式进行:
#define kDateAndHourUnitsComponents NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit
NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];
// for test and debug purpose
NSDateComponents* b = [calendar components:kDateAndHourUnitsComponents fromDate:retDate];
int a=[[calendar components:kDateAndHourUnitsComponents fromDate:theDate] weekday];
// -----------
if ([[calendar components:kDateAndHourUnitsComponents fromDate:theDate] weekday] == EKMonday) DoThis....
但这不起作用...... a 和 b 不包含任何有用的东西(a 等于 2147483647),
我也想知道[calendar components:NSWeekdayCalendarUnit fromDate:retDate]
在这种情况下,它的用途是什么,不再有用了......
我还发现这证实了这个过程: 如何检查星期几(即周二、周五?)并比较两个 NSDate?
我错过了什么 ?