NSDateFormatter를 사용하여 iPhone 앱에서 작업하고 있습니다. "00:00:00", "16:00:00","15:30:00" and so on
처럼 웹 서비스에서 시간을 얻고 있습니다. 시간이 "00:00:00" to "12 AM"
인 경우이 시간을 으로 변환하고, 시간이 "15:30:00"에서 "3.30PM"이면 "16:00:00" to "4 PM"
이면이 시간을 변환해야합니다. 나는 이것에 아래의 코드를 사용했지만 패스했을 때 "16:00:00" the date returns null
.오전/오후 형식으로 시간을 얻는 방법 iphone NSDateFormatter?
NSString *dats1 = @"16:00:00";
NSDateFormatter *dateFormatter3 = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter3 setDateStyle:NSDateFormatterMediumStyle];
[dateFormatter3 setDateFormat:@"hh:mm:ss"];
NSDate *date1 = [dateFormatter3 dateFromString:dats1];
NSLog(@"date1 : %@", date1); **// Here returning (null)**
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"hh:mm a"];
NSLog(@"Current Date: %@", [formatter stringFromDate:date1]); **// Here also returning (null)**
[formatter release];
"00:00:00"이 전달되면 "12 AM"이 올바르게 반환됩니다. 누구든지이 문제를 해결할 수 있도록 도와 주시겠습니까? 미리 감사드립니다.
답변을 게시하고 도와 주신 모든 분들께 감사드립니다. 당신은 모두 정확하게 대답하고이 문제를 해결할 수 있도록 도와주었습니다. 다시 한번 감사드립니다. – Gopinath
나는 당신의 정답 전부에 upvote를 주었다. 도움의 손길을 가져 주셔서 감사합니다. – Gopinath
정말'NSDateFormatter'에 대한 문서를 읽는 데 시간을 할애 했으므로 직접 대답 해 줄 수는 있습니다. –