How can I check if an NSDate is a specific day of the week, like a Monday, Tuesday, Wednesday, and so on?
+4
A:
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.
paxdiablo
2010-06-15 00:50:06
Your memory is quite well.
Hankweb
2010-06-15 01:00:51
Would 1 be Sunday, or would 0 be Sunday?
Hankweb
2010-06-25 05:00:46
It depends on your calendar, see http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSDateComponents_Class/Reference/Reference.html for details: Weekday units are the numbers 1 through n, where n is the number of days in the week. For example, in the Gregorian calendar, n is 7 and Sunday is represented by 1.
paxdiablo
2010-06-25 05:18:46