Possible Duplicate:
NSString to NSDate
How to parse a date string into an NSDate object in iOS
I have NSString *dateAndTime = @"2011-11-22 03:20:39".
I want to get a NSString *dateWithoutTime (e.g. "2011-11-22") from this above string.
How do I get?
Possible Duplicate:
NSString to NSDate
How to parse a date string into an NSDate object in iOS
I have NSString *dateAndTime = @"2011-11-22 03:20:39".
I want to get a NSString *dateWithoutTime (e.g. "2011-11-22") from this above string.
How do I get?
You can get the corresponding NSDate by
NSString *dateString = @"2011-11-22 03:20:39";
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDate *date = [dateFormat dateFromString:dateString];
[dateFormat release];
NSLog(@"%@",date);
But this has been answered so many times. Search the previous posts before asking a new question.
Use this
NSString *dateAndTime = @"2011-11-22 03:20:39";
NSString *date = [[dateAndTime componentsSeparatedByString:@" "] objectAtIndex:0];