2012-07-26 5 views
0

을 얻는 사람이NSFormatter 및 NSdate 문제가 발생했습니다. 있는 NSDate 객체는 null

입력 날짜를 도와주세요 수있는 이유를 알고 나는 날짜가 null 얻고 난 그나마 : @ "2012년 6월 14일을 - 세계 협정시 00시 00분 0초"

예상 출력 : @ "2012년 6월 14일"

   NSString *rawDate = @"June 14, 2012 - 00:00:00 UTC"; 
       NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 
       [dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]]; 
       [dateFormatter setDateFormat:@"MMMM dd, yyyy - HH:mm:ss"]; 
       NSDate *date = [dateFormatter dateFromString:rawDate]; 

       NSLog(@"Check the string date: %@", date); 

답변

1

이 밖으로 시도 : 당신은 입력 문자열의 시간대 부분에 대한 형식 식별자를 추가 할 필요가

NSString *rawDate = @"June 14, 2012 - 00:00:00 UTC"; 
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]]; 
[dateFormatter setDateFormat:@"MMMM dd, yyyy - HH:mm:ss Z"]; 
NSDate *date = [dateFormatter dateFromString:rawDate]; 

NSLog(@"Check the string date: %@", date); 

.