How to find last day of week in iphone -


in application m using following codes retrieve current date , day :-

nsdate *today1 = [nsdate date]; nsdateformatter *dateformat = [[nsdateformatter alloc] init]; [dateformat setdateformat:@"dd/mm/yyyy :eeee"]; nsstring *datestring11 = [dateformat stringfromdate:today1]; nslog(@"date: %@", datestring11); //[dateformat release]; nscalendar *gregorian11 = [[nscalendar alloc] initwithcalendaridentifier:nsgregoriancalendar];   nsdatecomponents *components1 = [gregorian11 components:nsweekdaycalendarunit | nsyearcalendarunit | nsmonthcalendarunit | nsdaycalendarunit fromdate:today1]; [components1 setday:([components1 day]-([components1 weekday]-1))];  nsdate *beginningofweek1 = [gregorian11 datefromcomponents:components1]; nsdateformatter *dateformat_first = [[nsdateformatter alloc] init]; [dateformat_first setdateformat:@"dd/mm/yyyy :eeee"]; nsstring *datestring_first = [dateformat_first stringfromdate:beginningofweek1];  nslog(@"first_date: %@", datestring_first); [components1 setday:([components1 day]-([components1 weekday]-1) + 6)]; =[gregorian datefromcomponents:components1]; [format setdateformat:@"dd/mm/yyyy :eeee"]; datestring = [format stringfromdate:now]; nslog(@" week last_date: %@", datestring); 

but using above code got current day , date , first day of week need last day of week. give wrong output plz told me m wrong m wrong in code , modification needed last day/date of week. please me out urgent.

when call setday: setting negative day. don't know if setday and/or datefromcomponents: handle that.

to create nsdate date/time in past (or future) can subtract (or add) number of seconds want go (or forward), this:

// convert seconds nstimeinterval tmpsecs = [[nsdate date] timeintervalsincereferencedate]; // shift date/time (in seconds) new date x days away: tmpsecs += daysoffset * 86400;  // 86400 seconds per day // convert nsdate , return result return [nsdate datewithtimeintervalsincereferencedate:tmpsecs]; 

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -