0

How to get this format of date from NSString;

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

Thanks

Luke
  • 11,426
  • 43
  • 60
  • 69
  • could you edit your question to clarify what you are trying to achieve? Are you formatting an NSDate object as an NSString? – hktegner Jun 22 '11 at 14:34

2 Answers2

3

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];
Chetan Bhalara
  • 10,326
  • 6
  • 32
  • 51
1

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.

Joe
  • 56,979
  • 9
  • 128
  • 135