iphone - 我怎样才能知道一个月有多少天?

标签 iphone

使用 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/

相关文章:

ios - 如何将 BGRA 字节转换为 UIImage 进行保存?

iphone - 如何从 iPhone 向 Windows 发送消息?

iphone - iTunes 评论 URL 和 iOS 7(要求用户评价我们的应用程序)AppStore 显示空白页面

iphone - 如何在分离的 UITableViewCell 和另一个 View 之间执行 segue

iphone - 在 ViewController.m 中,如何通过字符串访问在 ViewController.h 中声明的属性?

iphone - 将大量 Sqlite 行加载到 UITableView 中

ios - 从标签中删除缩进

iphone - CollectionView类View,可水平+垂直滚动

iphone - MonoTouch - System.Reflection.Emit.ModuleBuilder 错误

iphone - 在多任务模式下下载大数据?