1, can achieve time screening, visual should have more simple method.
Idea: Get the day time, and the target time to perform the action.
Note: Time zone time zone the time zone important time zone is said three times.
-(void) viewdidload {[Super viewdidload]; NSDate * today = [NSDate Date]; Define the current timezone time nsstring * times [email protected] "2015-08-16 00:00:00"; nsdate* xmlData = [self datefromstring:time]; XmlData = [self getnowdatefromatandate:xmldata]; if ([self intervalsincenow:xmldata]>=[self gettodayisweek:today]+7) {NSLog (@ "This date is long ago"); } if ([Self intervalsincenow:xmldata]>=[self gettodayisweek:today]&&[self intervalsincenow:xmldata]<[ Self gettodayisweek:today]+7) {NSLog (@ "This date is last week"); } if ([Self intervalsincenow:xmldata]<7&&[self intervalsincenow:xmldata]<[self getTodayisWeek:today]) {NSLog (@ "This date is this week"); }}-(int) Intervalsincenow: (NSDate *) thedate{nstimeinterval late=[thedate timeintervalsince1970]*1; nsdate* dat = [nsdate datewithtimeintervalsincenow:0]; dat= [self getnowdatefromatandate:dat]; Nstimeinterval Now=[dat timeintervalsince1970]*1; NSString *[Email protected] ""; Nstimeinterval cha=now-late; if (cha/86400>1) {timestring = [nsstring stringwithformat:@ "%f", cha/86400]; TimeString = [TimeString substringtoindex:timestring.length-7]; return [TimeString Intvalue]; } return-1; }-(NSDate *) Getnowdatefromatandate: (NSDate *) anydate{//Set source date time zone nstimezone* sourcetimezone = [Nstimezone timeZoneWi thabbreviation:@ "UTC"];//or GMT//set the converted target date time zone nstimezone* destinationtimezone = [Nstimezone localtimezone]; Get the offset of the source date and world standard Time Nsinteger sourcegmtoffset = [Sourcetimezone secondsfromgmtfordate:anydate]; The offset of the target date from the local time zone nsinteger destinationgmtoffset = [destinationTimeZone secondsfromgmtfordate:anydate]; Get the difference of time offset nstimeinterval interval = Destinationgmtoffset-sourcegmtoffset; Convert to present time nsdate* destinationdatenow = [[NSDate alloc] Initwithtimeinterval:interval sincedate:anydate]; return destinationdatenow;} -(NSDate *) datefromstring: (NSString *) Datestring{NSDateFormatter *dateformatter = [[NSDateFormatter alloc] init]; [Dateformatter Setdateformat: @ "Yyyy-mm-dd HH:mm:ss"]; NSDate *destdate= [Dateformatter datefromstring:datestring]; return destdate; }//gets the day of the week-(int) Gettodayisweek: (NSDate *) today{today = [self getnowdatefromatandate:today]; Nscalendar*calendar = [Nscalendar Currentcalendar]; Nsdatecomponents*comps; [Comps setweekday:0]; Comps =[calendar components: (nscalendarunitweekday) fromdate:today]; Nsinteger weekday = [comps weekday]; Day of the week (note that Sunday is "1", Monday is "2" .... ) int factweekday; Default is Sunday start switch (weekday) {Case 1:factweekday = 7; Break Case 2:factweekday = 1; Break Case 3:factweekday = 2; Break Case 4:factweekday = 3; Break Case 5:factweekday = 4; Break Case 6:factweekday = 5; Break Case 7:factweekday = 6; Break Default:break; } return factweekday;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
[IOS] Time filter < week, week, earlier >