2012-02-20 13 views
0

ファイルが24時間以上経過していれば、私はplistファイルを自動的に更新しようとしていますが、2つの日付の比較方法はわかりません。もし2つの日付を比較する文がある場合

if (date > fileModPlus24Hours) { 
    // update file 
} 

任意の提案:

// get last modification date 
NSString *dir = path; 
NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:dir error:nil]; 
NSDate *date = [attributes fileModificationDate]; 

NSDate *fileModPlus24Hours = [NSDate dateWithTimeInterval:(24*60*60) sinceDate:date]; 

のようなものをお考えですか?

答えて

0
if ([date compare:fileModPlus24Hours] == NSOrderedDescending) { 
    // update file 
} 

比較の結果は、NSOrderedAscendingNSOrderedDescending又はNSOrderedSameことができます。

そして、私はあなたのコードがdatefileModPlus24Hoursを比較するかどちらかで動作するとは思わないと思います。現在の日付をfileModPlus24Hoursに変更する必要があります。

NSDate *now = [NSDate date]; 
if ([now compare:fileModPlus24Hours] == NSOrderedDescending) { 
    // update file 
} 
+0

はい、あなたは正しいと思います。 Ttはあなたと協力しているようです。私は24時間以内にチェックします;-)ありがとう – ebsp

+0

実際には、今すぐチェックすることができます** **(** 24 * 60 * 60)** ** 60 ** **(1分)だけテストのために変更してから、 **(24 * 60 * 60)** :) – sch

関連する問題