다른 예제를 살펴본 결과이 문자열을 아직 날짜로 변환 할 수 없습니다.NSString을 NSDate로 변환하는 중 문제가 발생했습니다.
예측 변환 : 2012-07-01 0시 0분 0초 0000
타임 스탬프 변환 :이 코드를 실행 한 후 나는 NSLogs에서 다음과 같은 출력을 얻을 2012년 6월 24일 0시 0분 0초 0000
예측 : 604800.000000
내가 사용하는 하드 코딩 날짜가 없습니다. 아무도 이유를 아나요? 코드는 다음과 같습니다.
NSString *timeStamp = @"20120620 19:23";//[[predictionData objectAtIndex:0 ] valueForKey:@"tmstmp"];
NSString *predictionTime = @"20120620 19:30";// [[predictionData objectAtIndex:0 ] valueForKey:@"prdtm"];
NSDateFormatter *ts = [[NSDateFormatter alloc] init];
[ts setDateFormat:@"yyyyMMdd HH:dd"];
NSDate *convertedTS = [ts dateFromString:timeStamp];
NSDateFormatter *pt = [[NSDateFormatter alloc] init];
[pt setDateFormat:@"yyyyMMdd HH:dd"];
NSDate *convertedPT = [pt dateFromString:predictionTime];
NSTimeInterval timeDifference = [convertedPT timeIntervalSinceDate:convertedTS];
NSLog(@"Prediction Conversion: %@", [convertedPT description]);
NSLog(@"Timestamp Conversion: %@", [convertedTS description]);
NSLog(@"Prediction: %f", timeDifference);
감사합니다.
수 포맷터는 여전히 문자열에서 날짜와 시간이 잘못지고 해결해야한다. 내가 얻지 못합니다 예상 전환 : 2012-06-21 00:30:00 +0000 타임 스탬프 전환 : 2012-06-21 00:23:00 +0000 –