Date Format Problem

How to get this format of date from NSString;

Wed, 22 Jun 2011 12:36:00 +0100 to Wed, 22 Jun 2011.

Thanks

Upvotes: 0

Views: 393

Answers (2)

Chetan Bhalara
Chetan Bhalara

Reputation: 10344

Try this code.

NSString *dateStr = @"Wed, 22 Jun 2011 12:36:00 +0100";

    // Convert string to date object
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:@"EEE, d MMM yyyy HH:mm:ss ZZZ"];
    NSDate *date = [dateFormat dateFromString:dateStr];  

    // Convert date object to desired output format
    [dateFormat setDateFormat:@"EEE, MMM d YYYY"];
    dateStr = [dateFormat stringFromDate:date];
    NSLog(@"Date -- %@",dateStr);
    [dateFormat release];

Upvotes: 3

Joe
Joe

Reputation: 57179

The minimalistic version is E, d MMM y or to specify 2 digit days and 4 digit years E, dd MMM yyyy. The Date Formatter uses the Unicode Technical Standard #35.

Upvotes: 1

Related Questions