0
我試圖將消息calendarIdentifier發送到NSCalendar的實例。 這是我的代碼:(OBJ C)將消息calendarIdentifier發送到NSCalendar的實例並接收null
#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;
}
但是,由於某種原因,我得到這個在控制檯返回:
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
爲什麼我收到空?我試着環顧四周,但似乎無法找到任何東西。
感謝,