Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mikezang

macrumors 6502a
Original poster
May 22, 2010
854
7
Tokyo, Japan
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"];
 

Mvkoe

macrumors regular
Aug 4, 2008
103
3
Belgium
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"];

http://stackoverflow.com/questions/1775401/how-to-convert-nsdate-to-nsstring ?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.