2011-11-26 16 views
8

可能性の重複上の2つの日付の範囲内にあるかどうかを確認します。
How to compare two dates in Objective-C今日の日付は、iOSの

私は私のアプリケーションの1ときにメッセージをポップアップ表示したいのですが日付2つの日付の範囲内である(例えば休暇期間)

ので

if(dateInRangeof:date1, date2){True}else{false} 
のような

見るためのコードスニペットやapisを探しています。 乾杯

+1

チェックアウトこの[質問](http://stackoverflow.com/questions/949416/how-to-compare-two-dates-in-objective-c)、私はそれが非常に参考になりますね。 – Mousa

+2

私は重複としてこれを表示しません。以下の答えは特定の質問に簡潔に答えています。 – wuf810

答えて

35
- (BOOL)isDate:(NSDate *)date inRangeFirstDate:(NSDate *)firstDate lastDate:(NSDate *)lastDate { 
    return [date compare:firstDate] == NSOrderedDescending && 
      [date compare:lastDate] == NSOrderedAscending; 
} 
+8

これは包括的ではありません。 – nagem

+4

Swift: '' 'func isDate(date:NSDate、inRange fromDate:NSDate); &&!(日付比較:firstDate)== NSOrderedAscending)&&!([日付比較:lastDate] == NSOrderedDescending;)' toDateまで:NSDate、包括:ブール値) - >ブール{ かの包括的 { リターン(date.compare(fromDateから)== .OrderedAscending)&&(date.compare(toDateまで)== .OrderedDescending) }他 ! { return date.compare(fromDate)== .OrderedDescending && date.compare(toDate)== .OrderedAscending } } '' ' –

0

How to compare two dates in Objective-C

これは、あなたが探しているものでなければなりません。

NSDateのドキュメントを見ると、面白いことがたくさんあるはずです。

関連する問題