(OBJ C) 将消息 calendarIdentifier 发送到 NSCalendar 的实例并接收 null
(OBJ C) Sending message calendarIdentifier to an instance of NSCalendar and receiving null
我正在尝试将消息 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;
}
但是,出于某种原因,我在控制台中将其作为 return 得到:
2015-01-08 19:12:26.651 TimeAfterTime[1325:40863] This NSDate Object lives at 0x10010fe70
2015-01-08 19:12:26.656 TimeAfterTime[1325:40863] The date now is 2015-01-09 00:12:26 +0000
2015-01-08 19:12:26.656 TimeAfterTime[1325:40863] Seconds since 1970: 1420762346.651615
2015-01-08 19:12:26.656 TimeAfterTime[1325:40863] The date after 100,000 seconds
from 2015-01-09 00:12:26 +0000 is : 2015-01-10 03:59:06 +0000
2015-01-08 19:12:26.656 TimeAfterTime[1325:40863] My calender is (null)
Program ended with exit code: 0
为什么我得到的是空值?我试着环顾四周,但似乎找不到任何东西。
谢谢,
您需要为 initWithCalendarIdentifier:
初始值设定项提供已知的日历类型。仅提供任何字符串是行不通的。已知类型有:
NSGregorianCalendar
NSBuddhistCalendar
NSChineseCalendar
NSHebrewCalendar
NSIslamicCalendar
NSIslamicCivilCalendar
NSJapaneseCalendar
NSRepublicOfChinaCalendar
NSPersianCalendar
NSIndianCalendar
NSISO8601Calendar
这将为 identifier:
消息生成一个非空值。
我在 NSLocale.h
中找到了这些常量。
我正在尝试将消息 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;
}
但是,出于某种原因,我在控制台中将其作为 return 得到:
2015-01-08 19:12:26.651 TimeAfterTime[1325:40863] This NSDate Object lives at 0x10010fe70
2015-01-08 19:12:26.656 TimeAfterTime[1325:40863] The date now is 2015-01-09 00:12:26 +0000
2015-01-08 19:12:26.656 TimeAfterTime[1325:40863] Seconds since 1970: 1420762346.651615
2015-01-08 19:12:26.656 TimeAfterTime[1325:40863] The date after 100,000 seconds
from 2015-01-09 00:12:26 +0000 is : 2015-01-10 03:59:06 +0000
2015-01-08 19:12:26.656 TimeAfterTime[1325:40863] My calender is (null)
Program ended with exit code: 0
为什么我得到的是空值?我试着环顾四周,但似乎找不到任何东西。
谢谢,
您需要为 initWithCalendarIdentifier:
初始值设定项提供已知的日历类型。仅提供任何字符串是行不通的。已知类型有:
NSGregorianCalendar
NSBuddhistCalendar
NSChineseCalendar
NSHebrewCalendar
NSIslamicCalendar
NSIslamicCivilCalendar
NSJapaneseCalendar
NSRepublicOfChinaCalendar
NSPersianCalendar
NSIndianCalendar
NSISO8601Calendar
这将为 identifier:
消息生成一个非空值。
我在 NSLocale.h
中找到了这些常量。