5
votes

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?

2

2 Answers

6
votes
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!

2
votes
    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.