i want to separate out day month year time how will i do
NSString *datefromweb = [[tableArray objectAtIndex:indexPath.row ] objectForKey:@"ContentDateTime"];
NSDateFormatter *dateformatter = [[NSDateFormatter alloc] init];
[dateformatter setDateFormat:@"dd MMM yyyy HH:mm"];
NSDate *date1 = [[NSDate alloc] init];
date1 = [dateformatter dateFromString:datefromweb];
NSLog(@"date1=%@",date1);
[dateformatter setDateFormat:@"MMM yyyy"];
NSString *month1 = [dateformatter stringFromDate:date1];
[dateformatter setDateFormat:@"hh:mm a"];
NSString *time= [dateformatter stringFromDate:date1];
[dateformatter setDateFormat:@"dd"];
NSString *day1= [dateformatter stringFromDate:date1];
cell.day.text=day1;
cell.monthYear.text=month1;
cell.ldatetime.text=time;
we get string in datefromweb(NSString) variable but not get in datefromstring(NSDate) variable and i am separate out date,time,month,year.
my response is {ContentDateTime = "02 Jul 2016 5:12PM";}
dd MMM yyyy HH:mm
doesn't match02 Jul 2016 5:12PM
. Well, for the Day, Month and Year, it seems to, but not for the hours/minutes. Sodate1
should be nil. And so nothing after should work. You wrote yourself afterwardshh:mm a
, so you know how to get AM/PM, no? So the good format was something likedd MMM yyyy hh:mm a
. – Larme