使用 NSCalendar
或其他任何东西,是否可以获得给定 NSDate
的月份的天数?
最佳答案
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
关于iphone - 我怎样才能知道一个月有多少天?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3764962/