I have a date like this : Mon, 04 Jun 2012 14:13:00 GMT
and want to delete the time displayed so that I can have something like this : Mon, 04 Jun 2012
I tried the code below :
NSString *dateTex = [[stories objectAtIndex: storyIndex] objectForKey: @"date"];
NSLog(@"the object value is:%@",dateTex);
//changing dates format
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss Z"];
NSDate *date = [dateFormatter dateFromString:dateTex];
[dateFormatter release];
NSDateFormatter *dateFormatter2 = [[NSDateFormatter alloc] init];
[dateFormatter2 setDateFormat:@"EEE, dd MMM yyyy"];
NSString *dateText = [dateFormatter2 stringFromDate:date];
[dateFormatter2 release];
NSLog(@"the object value is:%@",dateText);
The date is parsed from an xml file and saved in the NSString dateTex. Then I am trying to change the format and save the new date on NSString dateText. However when I try to print the dateText variable, I get the object value is (null).
Any ideas?
You can try below code :
Welcome!