配列を解析していて、今までのレコードを除外したいと考えています。
私はこのコードを持っています:
int i = 0;
for (i=0; i < tempArray.count; i++) {
currentObjectArray = tempArray[i];
NSString *dateString = [currentObjectArray valueForKey:@"ScheduleTime" ];
NSDate *schedule = [dateFormatter dateFromString:dateString];
NSLog(@"schedule: %lu", (unsigned long) schedule );
NSLog(@"now: %lu", (unsigned long)[NSDate date] );
NSTimeInterval distanceBetweenDates = [schedule timeIntervalSinceDate: schedule];
NSLog(@"distanceBetweenDates: %lu", (unsigned long)distanceBetweenDates );
結果:
schedule: 16436914033316069376
now: 6174145184
distanceBetweenDates: 0
しかし、結果として得られる 2 つの数値は正しくないため、結果は正しくありません。誰かが私が間違っていることを教えてもらえますか? ありがとう
更新: 以下の回答のおかげで、コードを次のように更新しました。
NSString *dateString = [currentObjectArray valueForKey:@"ScheduleTime" ];
NSDate *schedule = [dateFormatter dateFromString:dateString];
float s = [schedule timeIntervalSince1970];
NSLog(@" %f", s );
NSTimeInterval timeInterval = [currentObjectArray timeIntervalSinceNow];
if (timeInterval > 0) {
NSLog(@"YES");
} else {
NSLog(@"NO");
The schedule date format is: "YYYY-MM-DD'T'HH:mm:ss"
Update2: ローカル タイム ゾーンを追加するのを忘れていました。すべての助けをありがとう。