[Solved] How to check time in between 4am to 4pm and 4pm to 4am in ios? [closed]


NSDateFormatter *dateFormat = [[NSDateFormatter alloc]init];
[dateFormat setTimeZone:[NSTimeZone systemTimeZone]];
[dateFormat setDateFormat:@"hh:mma"];


NSDate *now = [NSDate date];      // Current Date
NSString *time = [dateFormat stringFromDate:now];
NSString *fromDate = @"10:00AM";
NSString *toDate = @"11:00PM";
NSDate *fromTime = [dateFormat dateFromString:fromDate];
NSDate *toTime = [dateFormat dateFromString:toDate];
NSDate *nowTime = [dateFormat dateFromString:time];
NSDateComponents *fromComponents = [[NSCalendar currentCalendar] components:NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit fromDate:fromTime];
NSDateComponents *toComponents = [[NSCalendar currentCalendar] components:NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit fromDate:fromTime];
NSInteger fromHour = [fromComponents hour]; 
NSInteger toHour = [toComponents hour];
if (fromHour >= 4 && toHour <= 16) { 
    NSLog(@"4am to 4pm");
}
else{       
    NSLog(@"4pm to 4am");
}

solved How to check time in between 4am to 4pm and 4pm to 4am in ios? [closed]