如何将XML日期格式转换为Cocoa

我有日期格式:2009-08-10T16:03:03Z

我想转换为:@“MMM dd,HH:mm a”

我在NSString中检索xml格式。 我试图使用NSDateformatter:NSDateFormatter * df = [[NSDateFormatter alloc] init]; [df setDateFormat:@“MMM dd,HH:mm a”];

有任何想法吗?


NSString *yourXMLDate = @"2009-08-10T16:03:03Z" 
NSDateFormatter *inputFormatter = [[NSDateFormatter alloc] init];
[inputFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss"];
NSDate *inputDate = [inputFormatter dateFromString:yourXMLDate];
NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
[outputFormatter setDateFormat:@"MMM dd, HH:mm a"];
NSString *outputDate = [outputFormatter stringFromDate:inputDate];

希望这可以帮助!


    NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
    [dateFormatter setDateFormat:@"E, d LLL yyyy HH:mm:ss Z"]; // Thu, 18 Jun 2010 04:48:09 -0700
    NSDate *date = [dateFormatter dateFromString:self.currentDate];

    [item setObject:date forKey:@"date"];

    [items addObject:[item copy]];

这里编辑下面的代码

[dateFormatter setDateFormat:@"E, d LLL yyyy HH:mm:ss Z"]; // Thu, 18 Jun 2010 04:48:09 -0700

到你需要的格式。

链接地址: http://www.djcxy.com/p/35153.html

上一篇: How to Convert XML Date format to Cocoa

下一篇: NSDateFormatter returning nil in OS 4.0