在目标C中比较时间和日期 [英] Comparing time and date in objective C

查看:281
本文介绍了在目标C中比较时间和日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这是最常用的方法在预订/预订应用程序中查看是否已经占用了特定的时间段。

解决方案

尝试比较..



  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];

开关([dateOne比较:dateTwo]){
case NSOrderedAscending:
// NSLog(@NSOrderedAscending);
break;
case NSOrderedSame:
// NSLog(@NSOrderedSame);
{
break;
case NSOrderedDescending:
// NSLog(@NSOrderedDescending);
break;
}

[dateFormat release];


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 booking/reservation apps to see if that particular timeslot has been taken up etc.

解决方案

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];

这篇关于在目标C中比较时间和日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆