我正在一个项目中,我需要找出所选的时隙是否在另一个时隙之间。例如,有一个像1:00 AM到2:00 AM这样的时隙现在我想知道这个时隙是否在12:45 AM到3:45 AM时隙之间?

最佳答案

NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
[formatter setDateFormat:@"hh:mm a"];
NSDate *generatedStartDate = [formatter dateFromString:@"01:00 AM"];
NSDate *generatedEndDate = [formatter dateFromString:@"03:44 AM"];
NSDate *slotStartDate = [formatter dateFromString:@"01:00 AM"];
NSDate *slotEndDate = [formatter dateFromString:@"03:45 AM"];
NSComparisonResult result = [slotStartDate compare:generatedStartDate];
NSComparisonResult result1 = [generatedEndDate compare:slotEndDate];
if (result != NSOrderedDescending && result1 != NSOrderedDescending) {
    NSLog(@"IN Between");
} else {
    NSLog(@"NOT IN Between");
}

关于ios - 我怎样才能获得一个时隙是否在另一个时隙?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51767436/

10-10 12:31