How to display yesterDay (with respect to Date, but not time interval of 24 hours) visited items in iPhone objective c -
How to display yesterDay (with respect to Date, but not time interval of 24 hours) visited items in iPhone objective c -
i have table view contacts. in when select contact contact has added in table:recentstable. visited items. purposs have used code this, it's working but. in case of yesterday cosidered 24 hours. iwant display yesterday items when ever date changed automatically added in yesterday's list. please guide me.
nsdate *date = self.lastviewed; double time = [date timeintervalsincenow]; nsstring *tmpvalue = nil; time *= -1; if(time < 3600*24) { tmpvalue = @"today"; } else { int div = round(time / 60 / 60 / 24); // want solution wth respect yesterday's date date not follows if(div == 1) tmpvalue = @ "yester day"; if (div >1 && div <7) //tmpvalue= [nsstring stringwithformat:@"%d days ago", div]; tmpvalue = @"this week"; else if(div <30) tmpvalue = @"this month"; else tmpvalue = @"earlier"; }
thanks in advance..
you should utilize nsdatecomponents when working dates. handle things day lite savings etc. there plenty of questions on stackoverflow on nsdate, this one illustration can used solve problem changing date component -1 day.
nscalendar *gregorian = [[nscalendar alloc] initwithcalendaridentifier:nsgregoriancalendar]; nsdate *today = [nsdate date]; nsdatecomponents *daycomponent = [[nsdatecomponents alloc] init]; daycomponent.day = -1; nsdate *yesterday = [gregorian datebyaddingcomponents:daycomponent todate:today options:0];
iphone objective-c xcode nsdate nsdateformatter
Comments
Post a Comment