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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With