NSDateFormatter for IPhone

Discussion in 'iOS Programming' started by arnieterm, Oct 9, 2008.

  1. arnieterm macrumors regular

    Joined:
    Aug 28, 2008
    #1
    Hi all
    I am trying to generate an NSDate value by passing the below given string
    to the setDateFormat method of NSDateFormatter
    as show below
    Code:
    NSDateFormatter *dt=[[NSDateFormatter alloc]init];
    	[dt setFormatterBehavior:NSDateFormatterBehavior10_4];
    	[dt setDateFormat:@"yyyy-mm-dd HH:MM:ss +0000"];
    
    When I make use of
    dateFromString with the below given string
    "2009-02-01 00:00:00 +0000", it does not generate a valid date
    What's wrong with this date format?
    Thanks
     
  2. annguyen macrumors newbie

    Joined:
    Oct 2, 2008
    #2
    You probably used invalid date format pattern.
    Y = year
    M = month
    m = minute

    So your date format should be: "YYYY-MM-dd HH:mm:ss +0000".

    Cheers. :apple:
     

Share This Page