Comparing time and date in objective C

后端 未结 2 1175
暗喜
暗喜 2021-01-15 08:48

How do I compare in objective C to see if a certain time and date period overlaps another that is already in a plist for example?

This is most commonly used in booki

2条回答
  •  迷失自我
    2021-01-15 09:01

    Try this to Compare ..

    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
                [dateFormat setDateFormat:@"MM/dd/yyyy hh:mm:ss aa"];
    
    
    NSDate *dateOne=[dateFormat dateFromString:@"01/09/2011 11:12:10 AM" ];
            NSDate *dateTwo = [NSDate date];
    
            switch ([dateOne compare:dateTwo]){
                case NSOrderedAscending:
                    //NSLog(@"NSOrderedAscending");
                    break;
                case NSOrderedSame:
                    //NSLog(@"NSOrderedSame");
                 {
    break;
                case NSOrderedDescending:
                    //NSLog(@"NSOrderedDescending");
                    break;
            }
    
    [dateFormat release];
    

提交回复
热议问题