If NSDate is Monday

How to check if NSDate is a specific day of the week, like Monday, Tuesday, Wednesday, etc.?

+7
iphone nsdate
source share
1 answer

From memory (at the moment I don't have an ObjC environment):

int yourDOW = [[[NSCalendar currentCalendar] components:NSWeekdayCalendarUnit fromDate:yourDate] weekday]; if (yourDOW == 2) { ... } // Sun = 1, Sat = 7 

In other words:

  • Get current user calendar.
  • Get a block of the week depending on the given date.
  • Get a weekly day.
  • Compare this to what you want.
+16
source share

All Articles