ios-Learning points-Calendar tool class

Source: Internet
Author: User

#import<Foundation/Foundation.h>#import "monthModel.h"#import "dayModel.h"#import "SolarAndLunerHeader.h"@interfacePublicutils:nsobject#pragmaMark time localization + (NSDate *) Getlocaldatawithdata: (NSDate *) Date;#pragmaMark gets days + (Nsrange) Getrangefromsmallutilinbigutil: (NSDate *) Date;#pragmaMark obtains small units in large units of the coefficients, mainly used to obtain today according to the date is the day of the week, the default Setfirstweekday of 1 is starting from Sunday + (Nsinteger) Getcountfromsmallutilinbigutil: ( NSDate *) Date;#pragmaMark obtains the date of the first day of the current month + (NSDate *) Getcurrentmonthfirstday;#pragmaMark gets the date of the first day of the Month + (NSDate *) Getnextmonthfirstday;#pragmaMark assembles a blank data, and the month-to-date data does not change the package, the details of the data removed from the server to maintain the actual data + (Nsmutablearray *) Createfixedddata;#pragmaMark synchronizes month data, just week sync + (void) Copyweekwithdictionary: (Nsmutablearray *) array;@end
/*1.date Nsdatecomponents The time is localized by the Calendar 2. In turn, nsdatecomponents to date reverses the time that the turn-out time will go to the 0 time zone. Summary: local time to nsdatecomponents with a localized calendar, it is best to set the time zone of the calendar to 0 time zones, or 2 times the localization time error, and vice versa. */#import "PublicUtils.h"@implementationpublicutils#pragmaMark time localization + (NSDate *) Getlocaldatawithdata: (NSDate *) date{Nstimezone*timezone=[Nstimezone Systemtimezone]; Nsinteger interval=[timezone SECONDSFROMGMT]; return[Date Datebyaddingtimeinterval:interval];}#pragmaMark gets days + (Nsrange) Getrangefromsmallutilinbigutil: (NSDate *) date{Nscalendar*calendar =[Nscalendar Currentcalendar]; Nsrange Range=[Calendar Rangeofunit:nscalendarunitday inunit:nscalendarunitmonth fordate:date]; returnrange;}#pragmaMark obtains small units in large units of the coefficients, mainly used to obtain today according to the date is the day of the week, the default Setfirstweekday of 1 is starting from Sunday + (Nsinteger) Getcountfromsmallutilinbigutil: ( NSDate *) date{Nscalendar*calendar =[Nscalendar Currentcalendar]; return[Calendar Ordinalityofunit:nscalendarunitweekday inunit:nscalendarunitweekofmonth fordate:date];}#pragmaMark obtains the date of the first day of the current month + (NSDate *) getcurrentmonthfirstday{NSDate*date=[NSDate Date]; Nscalendar*calender=[Nscalendar Currentcalendar]; Nsdatecomponents*compt= [Calender Components: (nscalendarunityear| nscalendarunitmonth|nscalendarunitday) fromdate:date]; [Compt setday:1]; NSDate*currentdate=[Calender datefromcomponents:compt]; return[Publicutils getlocaldatawithdata:currentdate];}#pragmaMark gets the date of the first day of the Month + (NSDate *) getnextmonthfirstday{NSDate*date=[NSDate Date]; Nscalendar*calender= [Nscalendar Currentcalendar];//this does not have to be turned into 0 time zones .Nsdatecomponents *compt= [Calender components: (nscalendarunityear| nscalendarunitmonth|nscalendarunitday) fromdate:date]; if(compt.month== A) {[Compt setMonth:compt.month+1]; [Compt setYear:compt.year+1]; }Else{[Compt setMonth:compt.month+1]; } [compt Setday:1]; NSDate*currentdate=[Calender datefromcomponents:compt]; return[Publicutils getlocaldatawithdata:currentdate];}#pragmaMark gets each element from the date + (nsdatecomponents *) Changetocompontsfromdate: (NSDate *) date{Nscalendar*calender=[Nscalendar Currentcalendar]; [Calender settimezone:[nstimezone TIMEZONEFORSECONDSFROMGMT:0]];//(Set this purpose, pass in a local time, and then the local is the calendar to turn once, will cause 2 localization will have the error, so the calendar time zone to 0 time zone, to avoid 2 conversions)Nsdatecomponents *compt= [Calender components: (nscalendarunityear| nscalendarunitmonth| nscalendarunitday| nscalendarunithour| nscalendarunitminute|Nscalendarunitsecond) fromdate:date]; returncompt;}

ios-Learning points-Calendar tool class

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.