Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 615
tony.tc.leung Avatar asked Aug 10 '09 23:08

tony.tc.leung


1 Answers

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];

Hope this helps!

like image 87
lautaro Avatar answered Sep 25 '22 15:09

lautaro