How to Convert XML Date format to Cocoa
I have a Date format: 2009-08-10T16:03:03Z
that I want to convert to: @"MMM dd, HH:mm a"
I retrieve the xml format in an NSString. I tried to use the NSDateformatter: NSDateFormatter *df = [[NSDateFormatter alloc] init]; [df setDateFormat:@"MMM dd, HH:mm a"];
any ideas?
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]];
here edit the following code
[dateFormatter setDateFormat:@"E, d LLL yyyy HH:mm:ss Z"]; // Thu, 18 Jun 2010 04:48:09 -0700
to your required Format.
链接地址: http://www.djcxy.com/p/35154.html下一篇: 如何将XML日期格式转换为Cocoa