我有一个来自UIDatepicker的NSDate.
IBOutlet UIDatePicker *dueDate; NSDate *selectedDate = [dueDate date];
如何dueDate
以形式检索月份int
?(1月1日,2月2日等)
NSCalendar *calendar = [NSCalendar currentCalendar]; NSDateComponents *components = [calendar components:NSMonthCalendarUnit fromDate:[dueDate date]]; NSInteger month = [components month];
-[NSCalendar components:fromDate:]
例如,使用这里的例子:
http://developer.apple.com/iphone/library/documentation/Cocoa/Reference/Foundation/Classes/NSCalendar_Class/Reference/NSCalendar.html