阵列计时包含您的阵列。为了统一起见,您可能希望以 24 小时格式包含时间。
NSDateFormatter *dateFormatter = [NSDateFormatter new];
[dateFormatter setDateFormat:@"HH:mm"];
NSDate *now = [NSDate date];
__block NSString *status = nil;
[timings enumerateObjectsUsingBlock:^(NSDictionary * dict, NSUInteger idx, BOOL *stop)
{
NSDate *date1 = [dateFormatter dateFromString:dict[@"time_from"]];
NSDate *date2 = [dateFormatter dateFromString:dict[@"time_to"]];
NSDateComponents *date1Components = [[NSCalendar currentCalendar]components:NSHourCalendarUnit|NSMinuteCalendarUnit
fromDate:date1];
NSDateComponents *date2Components = [[NSCalendar currentCalendar]components:NSHourCalendarUnit|NSMinuteCalendarUnit
fromDate:date2];
NSDateComponents *nowDateComponents = [[NSCalendar currentCalendar]components:NSHourCalendarUnit|NSMinuteCalendarUnit
fromDate:now];
NSInteger fromMinutes = date1Components.hour*60+date1Components.minute;
NSInteger toMinutes = date2Components.hour*60+date2Components.minute;
NSInteger nowMinutes = nowDateComponents.hour*60+nowDateComponents.minute;
if (nowMinutes>fromMinutes && nowMinutes<toMinutes) {
status = dict[@"timing_name"];
}
}];
NSLog(@"%@",status);