unsigned units=nsmonthcalendarunit| Nsdaycalendarunit| Nsyearcalendarunit| Nsweekdaycalendarunit; Nscalendar *mycal=[[Nscalendar Alloc]initwithcalendaridentifier:nsgregoriancalendar]; NSDate*now=[NSDate Date]; Nsdatecomponents*comp =[mycal components:units Fromdate:now]; Nsinteger Month=[Comp Month]; Nsinteger Year=[comp year]; Nsinteger Day=[Comp Day]; Nscalendar*gregorian =[Nscalendar Currentcalendar]; Nsdatecomponents*datecomps =[Gregorian Components:nsweekdaycalendarunit Fromdate:now]; intDaycount = [Datecomps Weekday]-2; NSDate*weekdaybegin=[now addtimeinterval:-daycount* -* -* -]; NSDate*weekdayend =[now Addtimeinterval: (6-daycount) * -* -* -]; NSDateFormatter*df1=[[NSDateFormatter alloc]init]; Nslocale*mylocal=[[nslocale Alloc]initwithlocaleidentifier:@"ZH_CN"]; [Df1 setlocale:mylocal]; [Df1 Setdateformat:@"yyyy-mm-d"]; now=Weekdaybegin; Comp=[mycal components:units Fromdate:now]; Month=[Comp Month]; year=[comp year]; Day=[Comp Day]; NSString*date1=[[nsstring Alloc]initwithformat:@"%d-%02d-%02d", Year,month,day];//date requested for Mondaynow=Weekdayend; Comp=[mycal components:units Fromdate:now]; Month=[Comp Month]; year=[comp year]; Day=[Comp Day]; NSString*date2=[[nsstring Alloc]initwithformat:@"%d-%02d-%02d", Year,month,day];//date requested for Sunday
IOS calculates the start-to-date for this week