0

私はこのような時間の配列を持っています:

(
    "2000-01-01 23:48:00 +0000",
    "2000-01-01 02:15:00 +0000",
    "2000-01-01 04:39:00 +0000",
    "2000-01-01 17:23:00 +0000",
    "2000-01-01 13:02:00 +0000",
    "2000-01-01 21:25:00 +0000"
)

このコードから生成されるもの:

//loop through array and convert the string times to NSDates
                NSDateFormatter *timeFormatter = [[NSDateFormatter alloc] init];
                [timeFormatter setDateFormat:@"hh:mm a"];
                NSMutableArray *arrayOfDatesAsDates = [NSMutableArray array];
                for (NSObject* o in arrayTimes)
                {
                    NSLog(@"%@",o);
                    NSDate *nsDateTime = [timeFormatter dateFromString:o];
                    [arrayOfDatesAsDates addObject:nsDateTime];
                }
                NSLog(@"times array: %@", arrayOfDatesAsDates);//

次の配列で時間を取得しようとしているため、これを行っています。私の計画は、過去の時間を削除して並べ替え、最初の時間を次回として使用することです。

過去のものを削除するにはどうすればよいですか?

ありがとうございました

4

3 に答える 3

5

このようなものはうまくいきます...

NSArray *dateArray = ...

NSArray *filteredArray = [dateArray filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(NSDate *date, NSDictionary *bind){
    NSComparisonResult result = [[NSDate date] compare:date];
    return result == NSOrderedAscending; 
}]];

この場合、filteredArray は、現在または将来の dateArray からのすべての日付になります。

于 2013-07-04T21:54:44.910 に答える