我正在尝试将xml中的日期字符串解析为iPhone应用程序中的NSDate对象我知道必须先问过这个问题,但是,我相信我有正确的语法,但是没有用。我的代码有问题吗?我需要解析的日期字符串是: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 ];}任何帮助,不胜感激。谢谢!**根据来自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 回答
- 3 回答
- 0 关注
- 486 浏览
添加回答
举报
0/150
提交
取消