if NSDate is Monday
How can I check if an NSDate开发者_开发百科 is a specific day of the week, like a Monday, Tuesday, Wednesday, and so on?
From memory (I don't have an ObjC environment handy at the moment):
int yourDOW = [[[NSCalendar currentCalendar] components:NSWeekdayCalendarUnit
fromDate:yourDate] weekday];
if (yourDOW == 2) { ... } // Sun = 1, Sat = 7
In other words:
- Get the user's current calendar.
- Get the weekday unit based on the given date.
- Get the week day from that.
- Compare it with what you want.
精彩评论