,如果我有两个nsdatecomponent,我想知道,如果在第一个对象的时间比第二大。比较两个nsdatecomponent
例如:
if (nsdatecomponentObject1 > nsdatecomponentObject2)
{
//something
}
因为这样做不工作,我可怎么办呢?
,如果我有两个nsdatecomponent,我想知道,如果在第一个对象的时间比第二大。比较两个nsdatecomponent
例如:
if (nsdatecomponentObject1 > nsdatecomponentObject2)
{
//something
}
因为这样做不工作,我可怎么办呢?
在NSDateComponent
的NSDate
上使用compare:
。
if([[nsdatecomponentObject1 date] compare:[nsdatecomponentObject2 date]] == NSOrderedAscending)
权(唯一的)的方式来比较“上即时”两个NSDateComponents,是使用NSCalendar对象:
NSCalendar *gregorian = [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease];
switch([[gregorian dateFromComponents:oneNSDateComponents] compare:[gregorian dateFromComponents:anotherNSDateComponents]]) {
case NSOrderedSame:
NSLog(@"orderSame");
break;
case NSOrderedAscending:
NSLog(@"orderAscending");
break;
case NSOrderedDescending:
NSLog(@"orderDescending");
break;
}
什么意思的两个NSDateComponents比较同一月份,日期和年份是否有指定的工作日,而另一个没有?这些规则在哪里指定? – titaniumdecoy 2011-12-23 23:37:12