날짜 필드가있는 문자열이 있습니다. NSString 같은 필드를 2011-12-07 21:15:00 +0000과 같은 데이터베이스에 저장하고 있습니다. 나는 날짜 형식 문자열에서 날짜를 얻기 위해 다음 코드를 사용하고문자열의 NSDateFormatter를 변경하는 방법
같은 :
NSDateFormatter *dateFormat = [[[NSDateFormatter alloc] init] autorelease];
[dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss.S"];
나는 HH A와 시간 형식 위의 날짜 형식을 원하지만 항상 null을 제공합니다. 내 코드 :
NSDateFormatter *dateFormat = [[[NSDateFormatter alloc] init] autorelease];
[dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss.S"];
NSDateFormatter *timeFormat = [[[NSDateFormatter alloc] init] autorelease];
[timeFormat setDateFormat:@"hh a"];
[dateFormat setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"] autorelease] ];
NSDate *date1 = [dateFormat dateFromString:startSection];
NSLog(@"Date 1 : %@", date1);
[timeFormat setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"] autorelease] ];
NSDate *time1 = [timeFormat dateFromString:startSection];
NSString *strSection2 = [NSString stringWithFormat:@"%@", time1];
NSLog(@"Time 1 : %@", strSection2); /// always null at this place.
나는 내가 잘못 여기서 뭐하는 거지 모르겠습니다. 아무도 나를 도와 줄 수 없나요?
찾고있는 것을 의미합니다! 내가 제안한 것을 시도해 봤니? 너에게 효과가 있니? – Phlibbo
안녕하세요. Phlibbo. 도움을 주셔서 감사합니다. 그러나 내 것은 단지 지금까지 찾고있는 것 이상입니다. 코드를 작성해야하는 문자열을 정렬해야합니다. – lifemoveson
미안하지만 마지막으로 한 마디의 말을 이해할 수 없었습니다./ – Phlibbo