我有这两个NSDate
s:
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"MM/dd/yyyy"];
NSDate *rangeStart = [df dateFromString: @"03/03/2013"];
NSDate *rangeEnd = [df dateFromString: @"10/04/2013"];
而这个谓词:
request.predicate = [NSPredicate predicateWithFormat:@"createdDate >= %@ AND createdDate <= %@", rangeStart, rangeEnd];
但是,即使谓词的第二部分专门使用 a <=
,它也会返回直到前一天(即10/03/2013
)的对象。
我也尝试像这样构造谓词:
NSPredicate *dateStartPredicate = [NSPredicate predicateWithFormat:@"createdDate >= %@", rangeStart];
NSPredicate *dateEndPredicate = [NSPredicate predicateWithFormat:@"createdDate <= %@", rangeEnd];
NSPredicate *finalPredicate = [NSCompoundPredicate andPredicateWithSubpredicates:[NSArray arrayWithObjects:dateStartPredicate, dateEndPredicate, nil]];
但我得到了相同的结果。难道我做错了什么?这实际上是预期的行为吗?如果是,怎么能设置rangeEnd
到第二天呢?
谢谢