NSCalendar为所有值返回nil和0?

时间:2015-03-30 16:15:08

标签: ios objective-c

NSCalendar *cal = [[NSCalendar alloc] init];
NSDateComponents *tcomponents = [cal components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear|NSCalendarUnitMinute|NSCalendarUnitHour fromDate:[NSDate date]];

NSLog(@"-%@",cal); //gets null
NSLog(@"-%@",tcomponents); //gets null

它有什么不对吗?

1 个答案:

答案 0 :(得分:1)

您的日历不存在

指定的初始化程序是

- (id)initWithCalendarIdentifier:(NSString *)string

NSString * const NSGregorianCalendar;
NSString * const NSBuddhistCalendar;
NSString * const NSChineseCalendar;
NSString * const NSHebrewCalendar;
NSString * const NSIslamicCalendar;
NSString * const NSIslamicCivilCalendar;
NSString * const NSJapaneseCalendar;
NSString * const NSRepublicOfChinaCalendar;
NSString * const NSPersianCalendar;
NSString * const NSIndianCalendar;
NSString * const NSISO8601Calendar;

是有效的标识符。


或只是

NSCalendar *cal = [NSCalendar currentCalendar];