Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

if NSDate is Monday

Tags:

iphone

nsdate

How can I check if an NSDate is a specific day of the week, like a Monday, Tuesday, Wednesday, and so on?

like image 637
Hank Brekke Avatar asked Jun 15 '10 00:06

Hank Brekke


1 Answers

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.
like image 188
paxdiablo Avatar answered Nov 03 '22 09:11

paxdiablo