Reputation: 15778
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.
Upvotes: 10
Views: 7876
Reputation: 410722
You can use NSCalendar
and its rangeOfUnit:inUnit:forDate
method. For example, to get the number of days in the current month:
NSCalendar *calendar = [NSCalendar currentCalendar];
NSRange range = [calendar rangeOfUnit:NSDayCalendarUnit inUnit:NSMonthCalendarUnit forDate:[NSDate date]];
NSUInteger numberOfDaysInMonth = range.length;
Upvotes: 53