-(void) Viewdidload {
[superviewdidload];
nsstring *d =@ "2015-03-05 23:59:59";
nsdateformatter *format = [[nsdateformatteralloc] init] ;
[format setdateformat:@ "Yyyy:MM:dd HH:mm:ss"];
nsdate *date = [format datefromstring:d];
NSLog (@ "%i", [viewcontrolleriscurrentday:d ate]);
}
Determine if two time is the same day
+ (BOOL) Iscurrentday: (nsdate *) adate
{
if (adate==Nil) return NO;
nscalendar *cal = [ nscalendar currentcalendar ];
nsdatecomponents *components = [calComponents:(nscalendarunitera| Nscalendarunityear| Nscalendarunitmonth| Nscalendarunitday)fromdate: [nsdatedate]];
nsdate *today = [cal datefromcomponents: Components];
Components = [cal Components:(nscalendarunitera| Nscalendarunityear| Nscalendarunitmonth| Nscalendarunitday)fromdate: adate];
nsdate *otherdate = [cal datefromcomponents: Components];
if ([Today isequaltodate: otherdate])
return YES;
return NO;
}
How to tell if two time is the same day