Ben
Ben

Reputation: 969

NSDateformatter incompatible format

Tried almost everything and get null, the format I pass as parameter 'NSString' : WED 13-11-2013

-(NSDate*)stringToDate:(NSString*)dateString{

    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
//    [dateFormat setDateFormat:@"EE, d-LLLL-yyyy HH:mm:ss Z"];
//    [dateFormat setDateFormat:@"EE, dd-MM-yyyy"];
    [dateFormat setDateFormat:@"EEE, dd-MM-yyyy"];

//    NSString *str = [dateString stringByAppendingString:@" 09:00:00 +0000"];
//    NSDate *date = [dateFormat dateFromString:dateString];
    NSDate *date = [dateFormat dateFromString:dateString];


    return date;
}

Upvotes: 0

Views: 138

Answers (1)

Greg
Greg

Reputation: 25459

Hi try that it works for me:

-(NSDate*)stringToDate:(NSString*)dateString{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    dateFormatter.dateFormat = @"EEE dd-MM-yyyy ";
    [dateFormatter setLocale:[NSLocale currentLocale]];
    NSDate *date = [dateFormatter dateFromString:dateString];
    return date
}

Upvotes: 4

Related Questions