views:

125

answers:

1

Instead of calculating the month and leap year to do this calculation. Is there any way to check using some Apple Internal APIs to do so?

I found that the Java have something like this:

calendar.getActualMaximum(calendar.DAY_OF_MONTH) 

Is there any similar thing for Objective C? thz u.

+7  A: 

You can use NSCalendar and its rangeOfUnit:inUnit:forDate method. For example, to get the number of days in the current month:

NSCalendar *cal = [NSCalendar currentCalendar];
NSRange rng = [cal rangeOfUnit:NSDayCalendarUnit inUnit:NSMonthCalendarUnit forDate:[NSDate date]];
NSUInteger numberOfDaysInMonth = rng.length;
mipadi