compare:
2つの日付を比較してその結果を返します
-(NSComparisonResult)compare:(NSDate *)anotherDate:
解説
2つの日付を比較してその結果を返します。
【NSComparisonResult】
● NSOrderedAscending anotherDateの方が大きい
● NSOrderedSame 同じ
● NSOrderedDescending anotherDateの方が小さい
返り値
( NSComparisonResult )
比較
引数
( NSDate * )anotherDate
比較する時間
フレームワーク
Foundation
クラス
NSDate
Instance Methods
使用可能
10.0
参照
- earlierDate:
- isEqual:(NSObject protocol)
- laterDate:
例文
#import "MyObject.h" @implementation MyObject - (IBAction)myAction:(id)sender { NSDate *theDate1 = [NSDate dateWithString:@"2002-12-03 04:56:00 +0900"]; NSDate *theDate2 = [NSDate dateWithString:@"2002-12-04 04:56:00 +0900"]; switch ([theDate1 compare:theDate2]){ case NSOrderedAscending: NSLog(@"NSOrderedAscending"); break; case NSOrderedSame: NSLog(@"NSOrderedSame"); break; case NSOrderedDescending: NSLog(@"NSOrderedDescending"); break; } } @end