1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Help with Dateformatter and NSDate

Discussion in 'iPhone/iPad Programming' started by pashik, Nov 27, 2008.

  1. macrumors member

    #1
    Hello.
    i have date as string "Sat, 29 Nov 2008 00:00:00 -0500"
    and i'm trying to create NSDate from it with this code
    Code:
    [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"%a, %d %b %Y %H:%M:%S %Z"];
    NSDate *date = [dateFormatter dateFromString:@"Sat, 29 Nov 2008 00:00:00 -0500"];
    
    Date is always nil.

    Can someone help me with this?
     
  2. Moderator

    dejo

    Staff Member

    #2
  3. macrumors member

    #3
    I used also this format with same result - date is nil

    Code:
    @"EEE, dd MMM yyyy HH:mm:ss ZZ"
     
     
  4. Moderator

    dejo

    Staff Member

    #4
    You're starting by defining dateFormatter like so:
    Code:
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    correct?

    I tried the following code block and date was not nil:
    Code:
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss ZZ"];
    NSDate *date = [dateFormatter dateFromString:@"Sat, 29 Nov 2008 00:00:00 -0500"];
     
  5. macrumors member

    #5
    It looks like after installing sdk 2.2 date is not nil any more even if i set target sdk to 2.0.

    thank you.
     

Share This Page