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
它有什么不对吗?
答案 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];