我正在嘗試將xml中的日期字符串解析為iPhone應(yīng)用程序中的NSDate對(duì)象我知道必須先問過這個(gè)問題,但是,我相信我有正確的語(yǔ)法,但是沒有用。我的代碼有問題嗎?我需要解析的日期字符串是:2011-01-21T12:26:47-05:00我用來解析的代碼是:self.dateFormatter = [[NSDateFormatter alloc] init]; [self.dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]]; [self.dateFormatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] autorelease]]; [self.dateFormatter setDateFormat:@"yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"];... else if([elementName isEqualToString:kUpdated]){ self.currentQuestion.updated = [self.dateFormatter dateFromString:self.currentParsedCharacterData ];}任何幫助,不勝感激。謝謝!**根據(jù)來自ChrisKent的鏈接參考,我解決了以下問題:else if([elementName isEqualToString:kLastOnDeck]){ NSString *dateStr = self.currentParsedCharacterData; // we need to strip out the single colon dateStr = [dateStr stringByReplacingOccurrencesOfString:@":" withString:@"" options:0 range:NSMakeRange([dateStr length] - 5,5)]; self.currentQuestion.lastOnDeck = [dateFormatter dateFromString:dateStr];}
- 3 回答
- 0 關(guān)注
- 487 瀏覽
添加回答
舉報(bào)
0/150
提交
取消