文字列から NSDate を作成し、フォーマットして返す必要がある NSDate フォーマッターがあります。問題は、String から NSDate への変換の結果が間違っていることです。より大きな問題は、iPhone OS 3.1.2 では null を返し、シミュレーターでは間違った日付を返すことです。
//start formating date
NSMutableString *rawNewsDate = [NSMutableString stringWithString:@"Wed, 3 Feb 2010 14:47:11 CET"];
[rawNewsDate replaceOccurrencesOfString:@" CET" withString:@"" options:0 range:NSMakeRange(0, [rawNewsDate length])];
// Convert string to date object
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"EEE, d MMM YYYY HH:mm:ss"];
NSDate *date = [dateFormat dateFromString:rawNewsDate];
[dateFormat setDateFormat:@"d.M.YYYY | HH:mm"];
NSString *formatedDate = [dateFormat stringFromDate:date];
NSLog(@"Formated Date %@", formatedDate);
[dateFormat release];
コンソールのシミュレーターで、コードを実行した後、文字列から変換された NSDate は 2009-12-23 14:47:11 +0200 であり、フォーマットされたものは 23.12.2009 | です。14:47 .
コンソールのデバイスでは、文字列から変換された NSDate は null であり、フォーマットされたものも null です。
結果は 03.02.2010 | 14:47。
ポインタはありますか?ありがとう