2015-01-25 2 views
0

012-01-2010 00:00:00 +1100 이후로 경과 된 초를 NSTimeInterval으로 어떻게 얻을 수 있습니까?지난 날짜 이후로 초를 어떻게 받습니까?

// I need the function to use something like and am having an issue 

NSDate *aDate = (NSDate*)@"1980-01-01 00:00:00 +1100"; 
NSDate *seconds = [NSDate dateWithTimeInterval:60*60*24 sinceDate:aDate]; 
NSLog(@"seconds since Jan 1980 %@",seconds); 

// I am trying to replace the following 
//NSTimeInterval dateinterval = [[NSDate date] timeIntervalSince1970]; 

NSTimeInterval dateinterval = seconds; 

NSDate은 실제 응용에 도움이되지 않습니다 0000에서 GMT를 검색합니다. 현지 날짜는 필수 항목입니다.

이 방법이 너무 어렵습니까? 아니면 이렇게 할 수 없나요?

답변

0

NSDate 개체를 잘못 초기화하고 있습니다. 당신은 바로 당신 NSDateFormatter를 사용해야 NSDate 같은 NSString 캐스팅 할 수 없습니다

NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; 
formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss z"; 

NSDate *aDate = [formatter dateFromString:@"1980-01-01 00:00:00 +1100"]; 
NSDate *now = [NSDate date]; 

NSTimeInterval seconds = [now timeIntervalSinceDate:aDate]; 

새로운 NSDateFormatter를 사용하여 설정, 다른 시간대의 날짜를 포맷하기 위해 localtimeZone.

관련 문제