Why can't convert NSString to NSDate?

Discussion in 'iPhone/iPad Programming' started by mikezang, Jan 22, 2013.

  1. macrumors 6502a

    Joined:
    May 22, 2010
    Location:
    Tokyo, Japan
    #1
    I have a string is @"Tuesday, January 01, 2013", and I use code as below to convert it to date, but I only get nil, does anyone tell me why?
    Code:
    + (NSDate *)dateFromString:(NSString *)string withFormat:(NSString *)format {
    	NSDateFormatter *inputFormatter = [[NSDateFormatter alloc] init];
    	[inputFormatter setDateFormat:format];
    	NSDate *date = [inputFormatter dateFromString:string];
    	return date;
    }
    
    NSString *str = @"Tuesday, January 01, 2013";
    NSDate *date = [NSDate dateFromString:str withFormat:@"EEEE, MMMM dd, yyyy"];
    
     
  2. macrumors member

    Mvkoe

    Joined:
    Aug 4, 2008
    Location:
    Belgium
    #2
    http://stackoverflow.com/questions/1775401/how-to-convert-nsdate-to-nsstring ?
     
  3. thread starter macrumors 6502a

    Joined:
    May 22, 2010
    Location:
    Tokyo, Japan
  4. ArtOfWarfare, Jan 22, 2013
    Last edited by a moderator: Jan 22, 2013

    macrumors 603

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #4
  5. thread starter macrumors 6502a

    Joined:
    May 22, 2010
    Location:
    Tokyo, Japan
    #5
    Sure, I put that method in category NSDate+Helper
     

Share This Page