Format date with NSDateFormatter

Try this
First You need to convert this string back to NSDate then again convert the NSdate to string using formatter.

    NSDateFormatter *dateFormatForDB = [[NSDateFormatter alloc] init];
    [dateFormatForDB setDateFormat:@"dd-MM-yyyy HH:mm a"]; //Note capital H is 4 24-hour time format
    NSDate *aDate = [[[NSDate alloc] initWithTimeInterval:0 sinceDate:[dateFormatForDB dateFromString:aDateString]] autorelease];
   if(aDate){
     [formatter setDateFormat:@"MMM dd,yyyy"];
     NSString *date = [formatter stringFromDate:aDate];
     [dateFormatForDB release];
    }

Leave a Comment