Any way to find number of days in month using Objective C?
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.
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;
精彩评论