あり、本当にタイトルと一致どれもそこにいくつかの質問には、ですが、ここでは現在の時刻/日付を取得するには;-)
を行く:
NSDate *now = [NSDate date];
へこれを保存して、NSUserDefaultsに保存することをお勧めします:
[[NSUserDefaults standardUserDefaults] setObject:now forKey:@"startTime"];
[[NSUserDefaults standardUserDefaults] synchronize];
あなたはこのような関数を使用して2つの日付の差を見つけることができます
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"HH:mm"];
NSString *time = [formatter stringFromDate:theDate]; // returns something like @"10:30"
:
NSTimeInterval differenceInSeconds = [date1 timeIntervalSinceDate:date2];
後で
NSDate *theDate = [[NSUserDefaults standardUserDefaults] objectForKey:@"startTime"];
を使用して次のようなNSDateFormatterを使用して読める人間何かに日付をフォーマットすることができます
時間間隔は有益な時間に変換するため、分単位で60分、分単位で60分、時間単位で60分に分けて人間が読むことができます時間:
NSTimeInterval differenceInSeconds = ...
NSInteger totalSeconds = floor(differenceInSeconds);
NSInteger seconds = totalSeconds % 60;
NSInteger minutes = totalSeconds/60;
NSString *waitTime = [NSString strinWithFormat:@"%i minutes, %i seconds", minutes, seconds];
非常にありがとうございます。うん、私はちょうどそれを読んだタイトル/質問について申し訳ありません...すべての笑で本当に相関しない。約10時間スクリーンを見ていた。 – thebiglebowski11