谷歌XML解析器

  • 本文关键字:XML 谷歌 xcode
  • 更新时间 :
  • 英文 :


谁能帮我从解析的XML中获取格式化的日期。我可以使用NSXML格式化程序进行格式化,但现在我发现很难通过Google XMl解析器使用它。我可以通过键获取值,但我需要以格式化的方式获取它,

return [NSDictionary dictionaryWithObjectsAndKeys:
 [[[xmlItem elementsForName:@"title"] objectAtIndex:0] stringValue], @"title",
[[[xmlItem elementsForName:@"link"] objectAtIndex:0] stringValue], @"link",
    [[[xmlItem elementsForName:@"pubDate"] objectAtIndex:0] stringValue], @"Date",
                      nil];

在这里,pubDate 是从 xml 返回的,带有小时,分钟,秒我只需要日期。

提前谢谢!!!

我得到了答案

//cell.textLabel.text = [item objectForKey:@"pubDate"];
NSString *yourXMLDate = [item objectForKey:@"pubDate"];
NSDateFormatter *inputFormatter = [[NSDateFormatter alloc] init];
[inputFormatter setDateFormat:@"E, d LLL yyyy HH:mm:ss Z"];
NSDate *inputDate = [inputFormatter dateFromString:yourXMLDate];
NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
[outputFormatter setDateFormat:@"MMM dd, HH:mm a"];
NSString *outputDate = [outputFormatter stringFromDate:inputDate];
cell.textLabel.text=outputDate;

这导致 10 月 12 日凌晨 12:30。 无论 Xcode 中使用什么解析器,这都可以正常工作......

最新更新