cómo convertir la cadena de fecha en 2014-05-28T10: 51: 40.3056 + 01: 00 al formato dd-mmm-yyyy en ios

I'm very new to this ios. I want to convert 2014-05-28T10:51:40.3056+01:00 to 28-may-2014.But I'm getting null. please help me .

//here dateString is 2014-05-28T10:51:40.3056+01:00
NSString * dateString= [dict objectForKey:@"created_date"];

NSDateFormatter *df = [[NSDateFormatter alloc] init];
df.dateStyle = NSDateFormatterMediumStyle;
[df setDateFormat: @"yyyy-MM-dd'T'HH:mm:ss.SSS"];

NSDate *inputDate = [df dateFromString: dateString];
[df setDateFormat:@"dd-MMM-yy"];

NSString *    inputValue = [df stringFromDate:inputDate];

preguntado el 28 de mayo de 14 a las 11:05

2 Respuestas

Pruebe lo siguiente:

NSString * dateString = @"2014-05-28T10:51:40.3056+01:00";

    NSDateFormatter *df = [[NSDateFormatter alloc] init];
    df.dateStyle = NSDateFormatterMediumStyle;
    [df setDateFormat: @"yyyy-MM-dd'T'hh:mm:ss.SSSZ"];

    NSDate *inputDate = [df dateFromString: dateString];
    [df setDateFormat:@"dd-MMM-yy"]; //  [df setDateFormat:@"dd-MMM-yyyy"];

    NSString *inputValue = [df stringFromDate:inputDate];

Salida: 28-May-14

contestado el 28 de mayo de 14 a las 11:05

Well, I have been facing the same issue but then I split the Date string from . because it's not take the formate

NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
            [dateFormat setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss"];
            if ([dateFormat dateFromString:[[value componentsSeparatedByString: @"-"] objectAtIndex:0]] == nil) {
                value = [dateFormat dateFromString:[[value componentsSeparatedByString: @"-"] objectAtIndex:0]];
            } else {
                value = [dateFormat dateFromString:[[value componentsSeparatedByString: @"."] objectAtIndex:0]];
            }

contestado el 28 de mayo de 14 a las 11:05

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.