使用NSCalendar
os,是否可以获得给定NSDate
的月份天数?
答案 0 :(得分:5)
Get all days of any month with objective-c
显然,从那里复制,无论如何,我会把它保留在这里。
NSCalendar* a = [NSCalendar currentCalendar];
NSDateComponents* b = [[[NSDateComponents alloc] init] autorelease];
[b setMonth:1]; // The Month
NSRange c = [a rangeOfUnit:NSDayCalendarUnit
inUnit:NSMonthCalendarUnit
forDate:[a dateFromComponents:b]];
// c.length will have the amount of days
答案 1 :(得分:1)