2011-05-01 7 views
0

다음은 nsdate 포맷터의 코드입니다. 어떤 이유로 인해 dateSelected 값이 "April 30 2011 7:55 PM"대신에 잘못되었습니다. 2011-05-01 02:55 .. 어떤 생각을 잘못하고 있니?NSDate 형식 문제

NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init]; 
[outputFormatter setDateFormat:@"h:mm a"]; 
objEventInsert.eventtime = [outputFormatter stringFromDate:self.datePicker.date]; 
NSLog(@"%@",objEventInsert.eventtime); 
NSDateFormatter *dateForm = [[NSDateFormatter alloc] init]; 
[dateForm setDateFormat:@"LLLL d y h:mm a"]; 
NSDate *dateSelected = [dateForm dateFromString:[NSString stringWithFormat:@"%@ %@",objEventInsert.eventstartdate,objEventInsert.eventtime]]; 
NSLog(@"%@",objEventInsert.eventstartdate); 
objEventInsert.date = dateSelected; 
NSLog(@"%@",objEventInsert.date);

NSLog 응답 ... 올바른 UTC 시간의

2011-04-30 19:54:14.264 APP[24017:207] 7:55 PM 
2011-04-30 19:54:16.216 APP[24017:207] April 30 2011 
2011-04-30 19:54:17.654 APP[24017:207] 2011-05-01 02:55:00 +0000 

답변

1

귀하의 문제가 다시 새로운있는 NSDate를 작성하고 당신은 그냥 문자열을 통해 그것을 시작한다는 것입니다. 따라서 마지막 단계에서 문자열을 만들거나 NSDateFormatter를 다시 사용해야합니다.

NSString *dateSelected = [NSString stringWithFormat:@"%@ %@",objEventInsert.eventstartdate,objEventInsert.eventtime]; 
NSLog(@"%@", dateSelected); 

참고 : appendStringByFormat을 사용하면 코드를 간결하게 지정할 수 있습니다.