2011-04-19 2 views
1

이봐, 친구들은 많이 검색했지만 내 코드는 작동하지 않습니다.NSString (2011-04-18 18 : 57 : 47.453000)을 NSDate로 변환하십시오.

내가 좋아하는 형식의 문자열의 형태로 날짜를 얻고있다 : 2011-04-18 18 : 57 : 47.453000

나는 시간이 경과 계산할 수있는 NSDate이를 변환 할,하지만 난 얻을 수가 캔트 전환권. 내가 날짜 열을 인쇄 할 때

NSString *dateString = [entityData objectForKey:@"creation_time"]; 
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss.fff"]; 
NSDate *dateFromString = [[NSDate alloc] init]; 
dateFromString = [dateFormatter dateFromString:dateString]; 
[dateFormatter release]; 

내가 얻을 : 여기에 내가 뭐하는 거지입니다 2011-04-18 18 : 57 : 47.453000 하지만 인쇄 dateFromString 준다 : (널)

이 사람이 나를 지점 수 바른 길?

답변

5

당신은 아마 잠시 전에이 문제를 해결 ...하지만 :

날짜 구성 요소를 변환하는 방법에 대한 몇 가지 좋은 정보는 여기에 "날짜 필드 심볼 테이블"에서 찾아 볼 수있다
NSString *dateString = @"2011-04-18 18:57:47.453000"; 
NSDateFormatter *df = [[NSDateFormatter alloc] init]; 
[df setTimeZone: [NSTimeZone timeZoneWithAbbreviation:@"GMT"]]; 
[df setDateFormat:@"yyyy-MM-dd HH:mm:ss.SSSSSS"]; 
NSDate *dateFromString = [[NSDate alloc] init]; 
dateFromString = [df dateFromString:dateString]; 
[df release]; 

:

http://unicode.org/reports/tr35/tr35-6.html#Date_Format_Patterns

+0

Luke에게 회신 해 주셔서 감사합니다. 나는 이것을 결국 해결했지만 여기를 잊어 버렸다. – NSRover

관련 문제