views:

186

answers:

1

Hi,

I have an NSDate and I want to tell if it occurs on a particular day of any year. How do I do that?

For instance, I want to see if NSDate's day and month are 25 and 12.

I want to go:

NSDate *today = [NSDate date];    
int day = [today day];
int month = [today month];

Is there a way of doing that?

+2  A: 

You can use -[NSCalendar components:fromDate:] to do this:

NSDate                     *date = [NSDate date];
NSCalendar                 *cal = [NSCalendar currentCalendar];
int                        comp = NSMonthCalendarUnit |  NSDayCalendarUnit;
NSDateComponents           *cmpnts = [cal components: comp fromDate: date];

int                        day = [cmpnts day];
int                        month = [cmpnts month];
Ben Gottlieb