IOS Check if NSDate is today
NSDate *today = [NSDate date];
NSCalendar *gregorian = [[NSCalendar alloc]
initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *weekdayComponents = [gregorian components:(NSDayCalendarUnit | NSMonthCalendarUnit |NSYearCalendarUnit) fromDate:today];
NSInteger todayDay = [weekdayComponents day];
NSInteger todayMonth = [weekdayComponents month];
NSInteger todayYear = [weekdayComponents year];
BOOL res = NO;
//check if datedump is today
weekdayComponents = [gregorian components:(NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit)fromDate:dateDump];
NSInteger cday = [weekdayComponents day];
NSInteger month = [weekdayComponents month];
NSInteger year = [weekdayComponents year];
if (cday == todayDay &&
month == todayMonth &&
year == todayYear){
res = YES;
}
NSCalendar *gregorian = [[NSCalendar alloc]
initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *weekdayComponents = [gregorian components:(NSDayCalendarUnit | NSMonthCalendarUnit |NSYearCalendarUnit) fromDate:today];
NSInteger todayDay = [weekdayComponents day];
NSInteger todayMonth = [weekdayComponents month];
NSInteger todayYear = [weekdayComponents year];
BOOL res = NO;
//check if datedump is today
weekdayComponents = [gregorian components:(NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit)fromDate:dateDump];
NSInteger cday = [weekdayComponents day];
NSInteger month = [weekdayComponents month];
NSInteger year = [weekdayComponents year];
if (cday == todayDay &&
month == todayMonth &&
year == todayYear){
res = YES;
}
Comments
Post a Comment