Objective c (OBJ C)将消息calendarIdentifier发送到NSCalendar实例并接收null

Objective c (OBJ C)将消息calendarIdentifier发送到NSCalendar实例并接收null,objective-c,null,nsdate,nscalendar,Objective C,Null,Nsdate,Nscalendar,我正在尝试将消息calendarIdentifier发送到NSCalendar的实例。 这是我的代码: #import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { //Create a date instance. NSDate *now = [NSDate date]; NSLog(@"This NSDate Object lives at %p", now); NSLog(@"The

我正在尝试将消息calendarIdentifier发送到NSCalendar的实例。 这是我的代码:

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {

//Create a date instance.
NSDate *now = [NSDate date];
NSLog(@"This NSDate Object lives at %p", now);
NSLog(@"The date now is %@",now);

//Seconds from the date instance and 1970.
NSTimeInterval seconds_since_1970 = [now timeIntervalSince1970];
NSLog(@"Seconds since 1970: %f", seconds_since_1970);

//Future date from date instance.
NSDate *later = [now dateByAddingTimeInterval:100000];
NSLog(@"The date after 100,000 seconds from %@ is : %@", now, later);

//Create calender instance with user settings.
NSCalendar *cal = [[NSCalendar alloc] init];
NSString *calenderIdentity = [cal calendarIdentifier];
NSLog(@"My calender is %@", calenderIdentity);



return 0;
}
为什么我会变空?我试着四处看看,但似乎什么也找不到


谢谢,

您需要向
initWithCalendarIdentifier:
初始值设定项提供已知的日历类型。仅仅提供任何字符串都不起作用。已知类型包括:

NSGregorianCalendar
NSBuddhistCalendar
NSChineseCalendar
NSHebrewCalendar
NSIslamicCalendar
NSIslamicCivilCalendar
NSJapaneseCalendar
NSRepublicOfChinaCalendar
NSPersianCalendar
NSIndianCalendar
NSISO8601Calendar
这将为
标识符:
消息生成一个非空值

我在
NSLocale.h
中找到了这些常量

NSGregorianCalendar
NSBuddhistCalendar
NSChineseCalendar
NSHebrewCalendar
NSIslamicCalendar
NSIslamicCivilCalendar
NSJapaneseCalendar
NSRepublicOfChinaCalendar
NSPersianCalendar
NSIndianCalendar
NSISO8601Calendar