Monthly Archives: February 2009

Cocoa date functions are crazy

I thought Java was bad. Took me a while to figure this out and googling didn’t help, so I am just putting this out there for the next person who needs this.

To get the number of days in a month:

+ (NSInteger) getDaysInMonth:(NSDate*)date
{
    NSCalendar * cal = [NSCalendar currentCalendar];
    return [cal rangeOfUnit:NSDayCalendarUnit
        inUnit:NSMonthCalendarUnit forDate:date].length;
}