1

我正在获取两个日期之间的日期数组..执行此代码时出现错误不知道我哪里出错了:(

我的代码是

  NSArray *Dates = [NSArray arrayWithObjects:@"02-02-2012", @"04-02-2012", @"04-02-2012",      @"03-02-2012",@"04-02-2010", @"04-02-2012", @"04-02-2011", @"09-02-2012", @"12-02-2012 ",      @"11-02-2012", nil];
  NSString *startStringDate= @"03-02-2012";
  NSString *endStringDate = @"09-02-2012";

  //converting NSString to NSDate
  NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  [dateFormatter setDateFormat:@"dd-MM-yyyy"];
  NSDate *StartDate = [dateFormatter dateFromString:startStringDate];
  NSDate *endDate = [dateFormatter dateFromString:endStringDate];

 // output of StartDate is 03-02-2012 08:37:48 +0000
 // output of endDate is 09-02-2012 08:37:48 +0000

 //using filteredArrayUsingPredicate to fetch date which comes between StartDate and  endDate

  NSPredicate *findS = [NSPredicate predicateWithFormat:@"(SELF > %@) AND (SELF < %@)", StartDate, endDate];
  NSArray *result = [Dates filteredArrayUsingPredicate:findS];

当我运行此代码时,出现错误:[__NSDate length]: unrecognized selector sent to instance 0x982d5a0'

有人可以帮我解决这个问题 提前致谢

4

1 回答 1

3
NSArray *Dates = [NSArray arrayWithObjects:[dateFormatter dateFromString:@"02-02-2012"],[dateFormatter dateFromString:@"04-02-2012"],nil];

像这样为日期创建你的数组,而不是尝试它可能是有效的......

于 2012-04-19T09:54:21.137 回答