Get the time of week Monday Zero (the start of the week) and Sunday 24 o'clock (that is, the end of this week and the start of the next week)
NSDate *now =[NSDate Date]; Nscalendar*calendar =[Nscalendar Currentcalendar]; Nsdatecomponents*comp = [Calendar components:nsyearcalendarunit| Nsmonthcalendarunit| Nsdaycalendarunit| Nsweekdaycalendarunit|Nsdaycalendarunit Fromdate:now]; //get a day of the week//1 (Sunday) 2 (Tuesday) 3 (Wednesday) 4 (Thursday) 5 (Fri) 6 (Saturday) 7 (Sunday)Nsinteger WeekDay =[Comp weekday];//get What?Nsinteger Day =[Comp Day]; NSLog (@"weekday:%ld day:%ld", Weekday,day); //calculates the current date and the number of days between Monday and Sunday of the WeekLongFirstdiff,lastdiff;if(WeekDay = =1) {Firstdiff=1; Lastdiff=0;}Else{Firstdiff= [Calendar Firstweekday]-WeekDay; Lastdiff=9-WeekDay;} NSLog (@"firstdiff:%ld lastdiff:%ld", Firstdiff,lastdiff); //The number of days to add the difference on the current date (minus cent seconds)nsdatecomponents *firstdaycomp = [Calendar components:nsyearcalendarunit| Nsmonthcalendarunit|Nsdaycalendarunit Fromdate:now]; [Firstdaycomp setday:day+Firstdiff]; NSDate*firstdayofweek=[Calendar Datefromcomponents:firstdaycomp]; Nsdatecomponents*lastdaycomp = [Calendar components:nsyearcalendarunit| Nsmonthcalendarunit|Nsdaycalendarunit Fromdate:now]; [Lastdaycomp setday:day+Lastdiff]; NSDate*lastdayofweek=[Calendar Datefromcomponents:lastdaycomp]; NSDateFormatter*formater =[[NSDateFormatter alloc] init]; [Formater Setdateformat:@"YYYY-MM-DD HH:mm:ss"]; NSLog (@"Monday begins%@", [Formater Stringfromdate:firstdayofweek]); NSLog (@"Current%@", [Formater Stringfromdate:now]); NSLog (@"Sunday End%@", [Formater Stringfromdate:lastdayofweek]);