IOS calculates the start-to-date for this week

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.